Iterieren, ich habe ein großes Problem mit meinen Schleifen. Was das Programm macht: Das Programm liest eine Textdatei und gibt jeder Zeile der Textdatei ein Zeichenfolgenformat. Die Daten, die ich in der Zeichenkette haben möchte, sind durch Tabulatoren getrennt, so dass ich die Tabs durchsuche und alle Zeichen aufzählen muss, bis ich auf die erste Registerkarte klicke. Ich füge dann die Zeichen bis zum Tab hinzu und füge es zu einem Array hinzu, damit ich später die Daten auswerten kann.C++ While-Schleife nicht zur nächsten Zeile in der Textdatei
Meine innere while-Schleife analysiert meine erste Zeile korrekt, aber nicht zur nächsten Zeile in der Textdatei.
//Creates a temporary array
string current_line; //declare var line
string temp_string = "";
//When getline hits 'n' we are adding that to the string current_line
cout<<"Entering the Loop \n"<<endl;
// Gets the first line in the Text file and continutes to get each new line
// until we hit the end of file
while(getline(infile,current_line,'\n').good()){
//cout << "CURRENT SIZE " << current_line.size() << endl;
/* iterates through each character as long as the size of the current
line is greater than the counter i
*/
while(i < current_line.size()){
// If the Current character in the line is NOT a tab we add the
// character to string temp_storage
if(current_line[i] != '\t'){
temp_storage +=current_line[i];
}
/*If the Current Character in the line is a tab then we store
string temp_storage into another variable. Temp is cleared so we
can get the next word in the string
*/
else if (current_line[i] =='\t'){
Storage = temp_storage;
cout << "Current val: "<< Storage <<endl;
// Clears the temporary storage
temp_storage = "";
cout << "Clearing the temp_storage..."<< temp_storage<<endl;
}
//out << i << endl;
i++; // iterates the loop
}
cout<<"loop finished"<<endl;
}
// Hier ist die Ausgabe das Programm
Vielen Dank für das Lesen der laufenden!
nie zurücksetzen ich für die nächste Zeile –
@ArtemyVysotsky Ich habe total vermisst, danke, so viel! – Rustykatz
@MichaelBurr Will danke! – Rustykatz