permuteを呼び出すと、プログラムの下に、printという文字列に追加された都市名が表示されますが、空白のみが表示されます。Coutは自分の文字列を出力しません
このプログラムと同じくらい難しいのは、私のプリント機能が私に最も迷惑な問題を与えるとは思わなかったからです。あなたの都市が1、2、3の番号が付けられていた場合
は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;
}
:
その後、少しだけあなたのコードを変更します。代わりに、明示的にこのようなものを使用して、最初の
string
にcity
を変換します。それはちょうど約13の整数で構成されていて、何も表示していない文字列でなければなりません。 – Remixtこの質問をチェックして、 'int'と' string'をどのように連結するかを調べてください。また、次回は関係のないコードを削除してみてください。 –