我现在正在与string
in一起工作vector
。我让自己陷入了死胡同。我已经使用vector<int>
元素进行操作,并且了解如何使用它们!我知道如何使用string
!但是我无法通过需要更改向量中字符串元素值的部分。我的意思是我不知道如何loop
处理“做某事”。所以简而言之,我将任务交给我现在工作的女巫。
读取一系列单词cin
并将值存储在 中vector
。读取所有单词后,处理vector
并将每个单词更改为大写
这是我到目前为止所拥有的
int main ()
{
vector<string> words; //Container for all input word
string inp; //inp variable will process all input
while (cin>>inp) //read
words.push_back(inp); //Storing words
//Processing vector to make all word Uppercase
for (int i = 0; i <words.size(); ++i)
//do something
words[i]=toupper(i);
for (auto &e : words) //for each element in vector
//do something
cout<<e;
keep_window_open("~");
return 0;
}
第一条for
语句是不正确的,我尝试访问vector
元素并将单词更改为上部,但它对我不起作用,它只是示例
我尝试了很多方法来访问vector
元素,但是当尝试使用string
成员函数toupper()
时,vector
我变得一团糟代码和逻辑错误!
谢谢你的时间 。对不起,我在拼写单词时犯了错误