OK Ich habe eine txt-Datei, die wieWie kann ich zwei Strings entsprechen und eine ganze Zahl in eine Datei
Tacoma 0
Tacoma Seattle 15
Tacoma Spokane 24
Ich habe es so scheint, erklärt wie
inFile >> city1 >> city2 >> dist
Meine Frage ist, was muss ich tun, um mein Programm zu haben, meine zwei cin Stellen mit der txt-Datei zu ge übereinstimmen t die korrekte ganze Zahl in der dritten Spalte. Zum Beispiel war mein erster Cin-Standort Tacoma und mein zweiter Cin-Standort war Spokane, mein Ergebnis hätte 24 sein sollen, als ich in outFile < < dist codiert habe, aber ich bekomme als Ergebnis 0.
Gibt es ein Beispiel dafür. Ich brauche nicht jemanden, der meinen Code für mich schreibt, aber ein Beispiel, wie man das zur Arbeit bringt, würde mir helfen zu verstehen, was ich falsch gemacht habe.
int client()
{
string city1;
string city2;
int distance;
bool city1found = false;
bool city2found = false;
ifstream inClient;
ifstream inDist;
ifstream inroute;
ofstream outClient;
ofstream outDist;
inClient.open("client.txt", ios::app);
inDist.open("post.txt", ios::app);
outClient.open("client.txt", ios::app);
outDist.open("post.txt", ios::app);
inroute.open("routes.txt");
inroute >> city1;
inroute >> city2;
inroute >> distance;
cout << "Business Name (First & Last Name): ";
cin >> cFirst >> cLast;
outClient << cFirst << " " << cLast;
outDist << cFirst << " " << cLast;
cout << "Origin of delivery: ";
cin >> clocation;
if (clocation == city1) //if the current city is equal to the inputted from city
{
city1found = true;
}
else if (city1found == false)
{
cout << endl << "Origin city not found." << endl;
cin >> clocation;
}
outClient << "\t\t" << clocation;
outDist << setw(15) << clocation;
cout << "Seven digit phone number (EX. 671-689-5134): ";
cin >> cphone;
outClient << "\t\t" << cphone;
cout << "Email address: ";
cin >> cemail;
outClient << "\t\t" << cemail;
cout << "Destination of delivery: ";
cin >> cdestination;
if (cdestination == city2) //if the current city is equal to the inputted from city
{
city2found = true;
}
else if (city2found == false)
{
cout << endl << "Detination not found." << endl;
cin >> cdestination;
}
outClient << "\t\t" << cdestination;
outDist << setw(15) << cdestination;
cout << "Weight of Shipment(Tons): ";
cin >> weight;
outClient << "\t\t" << weight;
outDist << setw(15) << weight;
//Distance established
if (inroute.is_open())
{
while (!inroute.eof())
{
if (clocation && cdestination == city1 && city2)
{
distance;
}
}
}
outClient << "\t\t" << distance;
outDist << setw(15) << distance;
outClient << endl;
outDist << endl;
cout << "Order confirmed" << endl;
cout << "Enter '0' to return to the Main Menu or '1' to exit out of program" << endl;
cin >> ans;
if (ans == 0)
{
system("CLS");
main();
}
else (ans == 1);
{
exit(0);
}
}
Willkommen bei StackOverflow. Wir bevorzugen es, dass Sie uns Ihren Code und ein Beispiel mit der erwarteten Ausgabe zeigen, wie hier [http://stackoverflow.com/help/mcve] beschrieben, da es für uns einfacher ist, Sie zu verstehen und Ihnen zu helfen. Auch wenn Sie nicht wollen, dass wir eine Lösung für Sie schreiben. – Badda