question about File handling
Jan 13, 2013 at 10:31pm UTC
Please somebody tell me about the code of reading numbers from files, such as when i input to read email adress, it just read email adresses from a file
Jan 13, 2013 at 10:54pm UTC
Here are the steps:
Declare a std::ifstream object
use that object to open a file
check if the file has been opened
extract data from the file
close the file
1 2 3 4 5 6 7 8 9 10 11
#include <fstream>
#include <string>
//...
std::ifstream infile;
infile.open("Yourfile.txt" );
if (!infile.good())
return ;
std::string email;
infile>>email;
infile.close();
//note that the std::ifstream destructor closes the file when the object is being destroyed, so the line infile.close() is somewhat redundant.
Jan 14, 2013 at 9:15pm UTC
Thankyou very much. i willtry it
Topic archived. No new replies allowed.