First off, i have the .txt file that reads like this:
Abraham Jackson, 10, 15, 10, 13, 8, 18,
Joe Harrier, 13, 4, 5, 27, 12, 14,
Thomas High, 21, 2, 4, 15, 7, 3,
Jeffrey John, 4, 9, 8, 5, 27, 12,
Jason Smith, 3, 25, 8, 7, 4, 13,
$
My code (intended to read data from a .txt file and store it into arrays):
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
const int studentsSIZE = 5;
string students[studentsSIZE];
string stringscores[30];
ifstream inputFile;
inputFile.open("data.txt"); //OPEN THE .TXT FILE
int k = 0;
for (int i = 0; i < 5; i++) //READ AND STORE DATAS
{
(getline(inputFile, students[i], ',' ));
{
(getline(inputFile, stringscores[k], ','));
k++;
}
}
So far, I've got it to read the .txt file and stored all the names into the array(students) as intended.
My question is how do I remove the \n in the array.
Currently the array is storing the data like this:
{ "Abraham Jackson", "\nJoe Harrier", "\nThomas High", "\nJeffrey John", "\nJason Smith" }
Picture: https://i.stack.imgur.com/PxYxz.png
I have tried by putting inputFile.ignore() before line "(getline(inputFile, students[i], ',' )); " in order to remove the \n, but doing so caused program to remove the very first letter 'A' that it will read from the text file.
{ "braham Jackson", "Joe Harrier", "Thomas High", "Jeffrey John", "Jason Smith" }