Hey I'm a beginner at C++ and I'm trying to figure out how to read and display the content of a text file in my console application using C++. The file contains 25 lines and 3 columns. The first column is "Rank" (numerical values from 1 to 25) the second column is "Name" (25 teams name) and the third column "value" has the amount of point each team is worth. If someone could show me the code for reading and displaying all this information I would greatly appreciate it
The following block of code will read each line of a text file and write it to the console. You will need to figure out how to tokenize each line within the while loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
fstream fIn;
fIn.open( "c:\\SomeFile.txt", ios::in );
if( fIn.is_open() )
{
string s;
while( getline( fIn, s ) )
{
cout << s << endl;
// Tokenize s here into columns (probably on spaces)
}
fIn.close();
}
else
cout << "Error opening file " << errno << endl;
I have tried many different things I saw on google. Like using the getline with an ifstream or even displaying the entire file without reading each line, but it doesn't work. Apparently there's a problem because two of the columns are integer while the other is a string.when I try to build it, the output box says something like conversion impossible.