fstream - ifstream in c++ - compiler issues -


i transitioning c c++ , trying open , read input file , simultaneously assign variables values read in. example, have 6 variables: a, b, c, x, y,z , file: input.dat looks this:

1     2     3 4     5     6 

so in c write:

infile = fopen("input.dat","r"); fscanf(infile, "%d \t %d \t %d \n %d \t %d \t %d \n",&a,&b,&c,&x,&y,&z); 

i trying same thing in c++ using ifstream having trouble compiling simple program:

#include <iostream> #include <fstream>  using namespace std;  main(){     int a, b, c, x, y, z;      ifstream infile("input.dat", ifstream::in); //open input.dat in input/read mode       if(infile.is_open()){        /*read , assign variables file - not sure how yet*/        return 0;     } else {         cout << "unable open file." << endl;     }     infile.close();      return 0; } 

when try compile ton of errors thrown @ me like:

 "undefined reference std::cout" 

i sure silly mistake can't seem figure out. trying follow syntax described in examples at:http://www.cplusplus.com/doc/tutorial/files/

question:

1.how use fstream in above code?

2.how input files read , assigned variables. understand can done getline. possible use extraction operator >> , if so, syntax example?

unclear compilation (likely linking) issues aside, reading stream straightforward:

infile >> >> b >> c >> d >> e; 

will trick, assuming have data white-space delimited.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -