1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
ifstream fichier("d:\\SimuText.txt", ios::in); // on ouvre en lecture
// Array als Speicher für die Eingabe-Werte
int y_react [4] ;
// Eingabe Aufforderung aller Werte
for (int i = 0; i < 4;i++)
{
stringstream ss;
ss << (i+1);
string a = ss.str();
cout << "geben sie den " + a + "ten Wert ein:";
cin >> y_react[i];
}
if(fichier) // wenn das Öffnen der Datei funtioniert
{
// Zähler für die Zeilennummer
int lineNumber = 0;
vector<string> tokens; // Vektor zum Speichern der anhand des Tabulators zerlegten Zeile
while(!fichier.eof())
{
string content; // Inhalt der Zeile
getline(fichier, content); // on met dans "contenu" la ligne
lineNumber++;
if (lineNumber>1)
{
/// Start:Zeile zerlegt anhand Tabulator und in einem Vector "tokens" gespeichert. to be optimized for any kind of separators
string buf; // Have a buffer string
stringstream ss(content); // Insert the string into a stream
while (ss >> buf)
{
tokens.push_back(buf);
}
/// End: to be optimized for any kind of separators
if (!tokens.empty()&&tokens.size()==7)
{
string y_str = tokens.at(2);
int y;
istringstream ( y_str ) >> y;
// durchlaufe alle Eingabe-Werte, die im Array gespeichert sind
for (int j = 0; j < 4; j++)
{
// vergleiche jedes Array-Element mit dem aus der Zeile eingelesenen y-Wert
if (y == y_react[j])
{
cout << y_str+ " yuhu!! time=" + tokens.at(0) + "\n";
}
}
}
tokens.clear();
}
}
fichier.close();
}
else
cerr << "Impossible d'ouvrir le fichier !" << endl;
return 0;
} |
Partager