在調用置換函數後接近底部,我的程序應該打印已添加到我的打印城市字符串中的城市名稱,但它的唯一打印輸出空白。Cout將不會打印我的字符串
像這個程序一樣難,我沒有想到我的打印功能給我最討厭的問題。
int main()
{
string cities;
string printCity = "";
string line;
char command = 0;
unsigned city = 0;
while (getline(cin, line))
{
sscanf(line.c_str(), "%c %d", &command, &city);
if (command != 'c')
break;
cities.push_back((unsigned char)city);
printCity +=(city);
}
gFirstCity = cities[0];
unsigned to = 0;
unsigned from = 0;
uint32_t cost = 0;
sscanf(line.c_str(), "%c %d %d %d", &command, &to, &from, &cost);
graph[to][from]=cost;
graph[from][to]=cost;
while (getline(cin, line))
{
sscanf(line.c_str(), "%c %d %d %d", &command, &to, &from, &cost);
graph[to][from]=cost;
graph[from][to]=cost;
}
permute((char*)cities.c_str()+1, 0, cities.length()-1);
cout << "Minimum cost for the tour: ";
cout << printCity;
cout << " is: "<< minTour << endl;
return EXIT_SUCCESS;
}
那麼該置換功能,打印正確,唯一的問題是打印城市。它應該是一個由大約13個整數組成的字符串,但它沒有顯示任何內容。 – Remixt
請檢查這個問題,以瞭解如何連接'int'和'string's。此外,下次嘗試消除不相關的代碼。 –