這題我遇到的一些不懂的地方:
先貼上能Debug的代碼如下,這是參考網絡上的寫的
————————————————————————————————————————
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string text = ("Hello,my name is YJ1an.Nice to meet you!");
for (auto it = text.begin(); it != text.end(); ++it)
*it = toupper(*it);
cout << text << endl;
system("pause");
return 0;
}
——————————————————————————————————————————
但我如果想用vector<string>定義 text,就會出現很多問題:(如下代碼是有錯誤的)
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> text;
string word;
while (cin >> word)
text.push_back(word);
for (auto it = text.begin(); it != text.end() && !it->empty(); ++it)
*it = toupper(*it);
for (auto i : text)
cout << i << " ";
system("pause");
return 0;
}