I have to write a program to read from a tsv file and display the content of that file. I'm not sure where to start with this program. Please help, I'm lost.
20424297 1092 CSCI 13500 B 3
20424297 1092 CSCI 13600 A- 3.7
20424297 1092 FREN 10100 B 3
20424297 1096 FREN 10200 W -1
20424297 1099 CSCI 23500 NC -1
are the first 5 lines of the text. So far I've tried this
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{ifstream inStream;
inStream.open("StudentData.tsv");
if (inStream.fail())
{
cout << "file failed to open \n"
return (1);
}
while (inStream)
{
string ID;
inStream >> ID;
cout << "EmplID is" << ID;
}
return 0;
}
But it doesn't display anything and I'm not sure how to use that line you posted.
Is there any way to do it without getline though because my prof said "Both files are tab delimited (hence the tsv extension - tab separated values). And the data is structured so that you do not, actually you SHOULDN’T, have to use getline for your project."
> how did the number of records change between the 2 programs though?
Either a. scode and code are not all integers and/or num are not all numbers.
or b. there are some badly formed lines in the file.
If the assertion that "the data is structured so that you do not have to use getline for your project." is merely debatable, shouting "actually you SHOULDN’T" is unquestionably asinine.
Ideally, read the file line by line with error-handling.
Or if a 'career teacher' would penalise you for that, read everything in as strings (and then convert if required with std::stoi, std::stod.)