Hi :)
I have an assignment to create a battleship replica via code.
I'm trying to read my .csv file into my program, and I managed to remove
the commas, replacing them with a space. However, I do not know how to separate
the string and put them into my ship's objects.
The .csv files look like this
1 2
Battleship,A6,V
//Type of ship, location on grid, and vertical or horizontal.
Once you're changed the commas to spaces, the easiest way to parse each line is to use a stringstream.
10 11 12 13 14 15 16 17 18
for (int i = 0; i < 5; i++)
{ inFile >> temp;
replace(temp.begin(), temp.end(), ',', ' '), temp.end();
stringstream ss(temp);
ss >> type >> location >> horVer;
ships[i].settypeShip(type);
cout << ships[i].gettypeShip();
// Set the other attributes
}