Friday, 15 April 2011

Taking input from files in c++? -



Taking input from files in c++? -

i have file need take input in programme in c++.. file construction is

100 150 245 467 367 367

using get() reads first line...using get() 1 time again not help.. pls suggest best method it. thanks

see: http://en.cppreference.com/w/cpp/io/basic_ifstream

try this:

#include <fstream> #include <iostream> #include <string> using namespace std; int main() { ifstream stream("file.txt"); string foo; while(stream >> foo) cout << foo << endl; homecoming 0; }

output:

100 150 245 467 367 367

you can utilize stream operators extract 1 number @ time.

update question if doesn't reply kind of hard tell you're trying do.

c++

No comments:

Post a Comment