ShareThis

Saturday, November 26, 2011

How to read integer from file in c++ using ifstream?


C++ Syntax (Toggle Plain Text)


#include <fstream>
#include <iostream>


int main()
{
ifstream is("filename");
int input; 


if (is >> input)
std::cout << "Read " << input << '\n';


else
std::cout << "Couldn't read an integer\n";


}

0 comments:

Post a Comment