12 Apr
2004
12 Apr
'04
07:04
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