- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是遍历一个段落,直到遇到一个空行。
这是给我标题中提到的错误的代码
#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/
代码 A: vector::const_reverse_iterator rcit; vector::const_reverse_iterator tit=v.rend(); for(rcit = v
问题是遍历一个段落,直到遇到一个空行。 这是给我标题中提到的错误的代码 #include #include #include int main() { using namespace s
我在 MS visual studio 2005 的 Windows 上运行 Openipmp 客户端。尽管根据文档,它仅在 visual studio 6 和 MS visual studio .N
不幸的是,我的任务是编译一个旧的 C++ DLL,以便它可以在 Win 7 64 位机器上运行。我的 C++ 经验为零。我已经解决了其他问题,但是这个问题难倒了我,我还没有在其他地方找到解决方案。以下
将 VC6 代码迁移到 VS2008 时出现以下错误。此代码在 VC6 中运行良好,但在 VC9 中会出现编译错误。我知道这是因为编译器的破坏性变化。问题是什么,我该如何解决? error C2440
我收到以下错误: error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator' to 'DWORD' w
我遇到编译错误, required from 'std::pair, bool> std::_Rb_tree::_M_insert_unique(_Arg&&) [with _Arg = Soluti
我无法将元素插入 vector 。 void Addvec(const vector &v) { int num{}; cout>num; v.push_back(num);
我是一名优秀的程序员,十分优秀!