c++ - Getline string input to create a word -


i have program receives input , goes character through character avoid white spaces. need each 1 of characters aren't white spaces , stores them in string word.

someone told me getline stores each character, has memory:

then create while loop has (!= ' ')condition , use string.append('x') function "add" each character string variable you've created until have word.

i understand concept don't know how it.

here simple application takes string , filters out spaces.

// reading text file #include <iostream> #include <sstream> #include <fstream> #include <string> using namespace std;  int main () {   string input;   stringstream filter;   cout << "enter string \n";   cin >> input;   for(int = 0; i<input.length(); i++){       if(input.at(i)!=' '){ //chech see space or not           filter << input.at(i); //if not space add stringstream filter       }   }   string output = filter.str(); //final string no spaces    return 0; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -