我正在尝试制作一个程序,它将从用户那里获取数量和单词的列表。但是,我已经完成了所有工作,但无法将数字与同一行中的相应单词组合在一起。它继续输出所有的数字,然后输出所有的单词。单词也应该按字母顺序输出。先感谢您!
{
set<string> sortedItems;
cout << " (type \"exit\" to exit, now press enter to begin listing): ";
getline (cin, qtyChoice);
getline(cin, itemChoice);
for (int i = 1; ; i++)
{
string itemChoice;
string wholeOrder;
cout << i << ". ";
cin >> itemChoice;
cin >> qtyChoice; // this is how I got it to take #'s
if (itemChoice == "exit")
{
break;
}
sortedItems.insert(qtyChoice);
sortedItems.insert (itemChoice);
for_each(sortedItems.begin(), sortedItems.end(), &print);
return 0;
}
它不是在同一行输出每个的数量和每个的名称,而是这样做:
1. 23 hello
2. 18 thanks
3. 37 goodbye
4. exit
exit
18
23
37
goodbye
hello
thanks