I would like to outout each line after a certain substring is detected. Somehow I get a fivefold output for iss
. Here's my code:
//load all data from txt
string data;
std::ifstream infile("SavedData.txt");
while (std::getline(infile, data)) {
std::istringstream iss(data);
string d;
while (iss >> d) {
//extract substring
unsigned firstBracket = data.find("(");
unsigned lastBracket = data.find(")");
string coordSynth = data.substr(firstBracket + 1, lastBracket - firstBracket - 1);
cout << coordSynth << endl;
}
}
The output right now is like:
0.0, 45.0, -390.0
0.0, 45.0, -390.0
0.0, 45.0, -390.0
0.0, 45.0, -390.0
0.0, 45.0, -390.0
0.0, 45.0, -314.3
0.0, 45.0, -314.3
0.0, 45.0, -314.3
0.0, 45.0, -314.3
0.0, 45.0, -314.3
etc.
Actually I just want
0.0, 45.0, -390.0
0.0, 45.0, -314.3
0.0, 45.0, -277.3
etc.
And no, in the txt file there aren't duplcates. This file looks like this:
0001(0.0, 45.0, -390.0).png
0003(0.0, 45.0, -314.3).png
0007(0.0, 45.0, -277.3).png (and so on...)