確定我有一個看起來像這樣我怎麼兩個字符串和整數匹配到一個文件
塔科馬塔科馬0
塔科馬西雅圖15
塔科馬斯波坎24
我把它宣佈一個txt文件這樣
INFILE >> city1 >>城2 >> DIST
我的問題是什麼,我需要做的有我的節目我的兩個CIN位置匹配到txt文件到GE t第三列的正確整數。作爲一個例子,我的第一個cin位置是塔科馬,我的第二個cin位置是斯波坎,我的結果應該是24,當我編碼outFile < < dist,但我一直得到0。
有沒有這樣的例子。我不需要有人爲我編寫代碼,但是如何讓這個工作起作用的例子將幫助我理解我一直在做錯的事情。
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);
}
}
歡迎來到StackOverflow。我們更喜歡你向我們展示你的代碼和一個帶有如[這裏](http://stackoverflow.com/help/mcve)所述的期望輸出的例子,因爲我們更容易理解和幫助你。即使你不希望我們爲你寫一個解決方案。 – Badda