how do we define "space"as a character such that when there is a space between 2 words, it is taken as a character ???
thanks
godfather
how do we define "space"as a character such that when there is a space between 2 words, it is taken as a character ???
thanks
godfather
Well, standard cin eats whitespace, if you want to get whitespace, either use cin.getline to grab an entire input string, or cin.get to get a character regardless of type.
Depends what you are talking about... space on input... space on output...
if you had a space in a file...
...Your spaces would be counted as characters and loaded into the character array.Code:... ifstream ins; char c[100]; int i=0; ... while ( (!ins.eof()) && (i<100) ) { ins.get(c[i]); ++i } ...
What are you trying to do exactly?
Blue
use ifstream::operator<<() then ifstream::get() back and forth.
ie:
to deal with more than one whitespace character, instead of doing that fin.get(), do this:Code:while (fin.good()) { fin << word;//read everything till whitespace (' ','\n','\t') if (fin.get() == ' ') cout << "Space\n";//read only the next whitespace (beware there could be more) }
just some simple work around to using getline() for the entire line and get() for each character.Code:do fin.get(); while (fin.peek() == ' ' || fin.peek() == '\n' || fin.peek() == '\t');