I want to read in lines from a text file which have the following format:a r3, r2, r1
and i want to split this into individual pieces so i have a variable which holds a, r3, r2, and r1 individually, so i need to remove the whitespace and comma. Im not sure how to do this. I've searched around but could only find examples (like this) with pre-defined strings.
I know how to read in a text from a file and place it into a char array, but ideally i'd like to place each element of a line into a separate variable.
So something like:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void main()
{
string var1, var2, var3, var4;
ifstream inFile("myfile.txt");
if (inFile.is_open()){
while (!inFile.eof()){
inFile >> var1 >> var2 >> var3 >> var4;
}
}
}
but where it handles whitespaces, commas, and new lines. Any suggestions on how to do this?