hi..
i need to read a file..
in tat file i ve to read all strings and compare it with the given string..
hw 2 read strings in file exculding whitespaces n compare it..?
help me...!!!!

Recommended Answers

All 6 Replies

use the >> operator

ifstream in("file.txt");
string word;
while( in >> word )
{

}

can u explain it please...........

What don't you understand? I could write pages and pages explaining what's happening, but that won't help as much as a pointed answer to a pointed question. ;)

For reading: Link
For comparison: Link
And you have the information given by Ancient Dragon.Use "word" in his example as a string class object.

can u explain it please...........

The code snippet I posted opens a text file and reads it one word at a time. What I did not post was the requirement to compare the words read with some other string -- I left that up for you to do.

The code snippet I posted opens a text file and reads it one word at a time. What I did not post was the requirement to compare the words read with some other string -- I left that up for you to do.

thank you....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.