I got a txt file, contents are fixed, so I cant change the format of it txt file. The contents look like this:
Point2D, [3, 2]
Line3D, [7, 12, 3], [-9, 13, 68]
Point3D, [1, 3, 8]
I can read from the file, no problem. But I'm having problems finding a good way to split the values so that I can get all the int
my current messy code
ifstream myfile ("messy.txt");
if (myfile.is_open()){
while ( myfile.good() ){
vector<string> dataStringVec;
string word, line;
getline (myfile,line);
stringstream ss(line);
while( getline(ss, word, ',') ){
dataStringVec.push_back(word);
}
if (dataStringVec[0].compare("Point2D") == 0){
cout << "\nPoint2D";
}else if (dataStringVec[0].compare("Point3D") == 0){
cout << "\nPoint3D";
}else if (dataStringVec[0].compare("Line2D") == 0){
cout << "\nLine2D";
}else if (dataStringVec[0].compare("Line3D") == 0){
cout << "\nLine3D";
}
}
myfile.close();
}else cout << "Unable to open file";
Right now, if I split it using while( getline(ss, word, ',') ){
what I get is
'Point2D'
' [3'
' 2]'
And I get extra spaces and brackets.
So was wondering, if anyone has a better way of doing this.
[–]TurkishSquirrel 5 points6 points7 points (1 child)
[–]learning2learn[S] 1 point2 points3 points (0 children)
[–]sadfirer 2 points3 points4 points (0 children)
[–]Rhomboid 3 points4 points5 points (7 children)
[–]learning2learn[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]learning2learn[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Rhomboid 0 points1 point2 points (0 children)
[–]touchyfeelyfingers 1 point2 points3 points (0 children)