I need to read in from a comma-separated .txt file where each line looks something this:
1234,0987,Bob,23.45
(ie int,int,string,double)
using the following setup code:
fstream myFile;
myFile.open("textfile.txt" , ios::in);
if (myFile.is_open()) {
//read in characters as appropriate type until ','
}
I have tried using
myFile >> int1 ......
but I was unsure how I should deal with the commas; they may get filtered out when reading in integers, but would that work when I get to the string?
one of my classmates suggested stringstream, but i’ve found the documentation on cplusplus.com to be over my head.
You might want to try out the
std::getlinefunction:(From http://www.cplusplus.com/reference/string/getline/)