how to get the text from file before any space come
suppose i have file and it reads
Code:
aa this is a
bb this is b
cc this is c
i am only interested in aa, bb, cc not the rest of the text. or in other words ignore the text that is after space.
so i came up with this code
Code:
std::ifstream file("abc.txt");
std::string str;
while (file >> str /* read next word */)
{
std::cout << str << std::endl;
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); /* ignore rest of line */
}
but there is problem, Is there any such a method in which I can use before or after this file.ignore(), to actually keep the rest of the line? I mean, the rest of the line shall be used.
Considering that the first column of the text file is an integer, something inside of the while loop like:
Code:
value = atoi(str.c_str());
(if value==1){
cout <<restOfTheLine<<endl;
}
i am only interested in aa, bb, cc not the rest of the text. or in other words ignore the text that is after space.
[...]
but there is problem, Is there any such a method in which I can use before or after this file.ignore(), to actually keep the rest of the line? I mean, the rest of the line shall be used.
Errr, now what do you want: discard it or keep it?
At any rate, this question has nothing to do with C++/CLI, the .NET variant of C++, which the forum section here is about. It would much better be placed in the Non-Visual C++ section. So I suggest you repost it there, unless a moderator spots it first and moves it.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks