I define the constant string. Then i want to compare string from file with this constant string. The file contain many line. Each line contain string and integer. It must search the same string with the string that defined before, so i can get tha value of integer to execute. This is the example of file contain: Tom 30 Mike 40 Ivan 35 etc.... What must i do? thanks before. --------------------------------- Do you Yahoo!? Yahoo! Tax Center - File online by April 15th
fajar sss wrote:
I define the constant string. Then i want to compare string from file with this constant string. What must i do? thanks before.
Include file stream support with: #include<fstream> To open a file "fred" for reading: std::ofstream file( "fred" ); This returns 0 if the file couldn't be opened. To close a file: file.close(); To check if you've reached the end of the file: if( file.eof() ) /* end of file */; To handle strings, use the string class because it allows you to easily compare strings: std::string name = "Tom"; if( name == "Fred" ) To read from the file: string name; int number file >> name; file >> number; or file >> name >> number; -- JDL
participants (2)
-
fajar sss
-
John Lamb