Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <vector>
- #include <bits/stdc++.h>
- string char_vector_method(string input){ //using vectors
- vector<char> vec;
- int index = 0;
- while(index<input.size()){
- if(!isspace(input.at(index))){
- vec.push_back(input.at(index));
- }
- index++;
- }
- input = "";
- for(int i = 0; i<vec.size(); i++){
- input+=vec.at(i);
- }
- return input;
- }
- string string_count_method(string input){ //stl library
- int lenght = input.size(), counted = count(input.begin(), input.end(), ' ');
- remove(input.begin(), input.end(), ' ');
- input.resize(lenght - counted);
- return input;
- }
- int main(){
- string input;
- getline(cin, input);
- cout<<"Char arr method: "<<char_vector_method(input)<<endl;
- cout<<"Stl method: "<<string_count_method(input)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement