question about File handling

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
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.
Thankyou very much. i willtry it
Topic archived. No new replies allowed.