Skip to content
Snippets Groups Projects
Commit 54f9cbcc authored by Mattia Livraghi's avatar Mattia Livraghi
Browse files

Add sampleParser.cpp

parents
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <string>
#include <fstream>
using std::cout;
using std::endl;
using std::string;
using std::ifstream;
int main(void)
{
ifstream in;
string fileName = "nums.txt";
in.open(fileName);
// check the file was successfully opened for reading; quit upon failure
if(!in.is_open())
{
cout << "Cannot open file" << endl;
return 1;
}
string a,b,c,d;
float num;
// the first line of the file contains headers that must be read into a
// string, rather than a float -> read the headers separately
in >> a >> b >> c >> d;
in >> num; // first reading operation before the loop, so that its
// success can be checked as the entry condition of the loop
// this loop will exit upon reading failure
while(in) // alternative: while(!in.fail())
{
/* do something with num */
in >> num;
}
in.close();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment