gpt4 book ai didi

c++ - 编译错误,提示 'std::basic_string

转载 作者:行者123 更新时间:2023-11-28 00:43:55 25 4
gpt4 key购买 nike

问题是遍历一个段落,直到遇到一个空行。

这是给我标题中提到的错误的代码

#include <iostream>
#include <string>
#include <vector>
int main()
{
using namespace std;
string word;
vector<string>text;
while(cin>>word)
{
text.push_back(word);
}
for(auto it = text.begin(); it != text.end() && !(*it).empty; it++)
{
cout<<*it<<endl;
}
}

导致错误的原因是什么,修复方法是什么?

我是初学者,刚开始使用迭代器。

最佳答案

empty 是一个函数。

#include <iostream>
#include <string>
#include <vector>
int main()
{
using namespace std;
string word;
vector<string>text;
while(cin>>word)
{
text.push_back(word);
}
for(auto it = text.begin(); it != text.end() && !(*it).empty(); it++)
{
cout<<*it<<endl;
}
}

关于c++ - 编译错误,提示 'std::basic_string<charT, _Traits, _Alloc>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17358956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com