Strings in C++: Problems with good() and get()
I am trying to read from a file. The code I used is
ifstream is;char c;
is.open("text.txt");
while(is.good() && !isdigit(is.peek()))
{ is.get(c)
word+=c;
}
The problem is that the last character is read twice (why?) For e.g. if
the word in the file is pink the value of word becomes pinkk after the
loop Please suggest a solution
No comments:
Post a Comment