|
5鱼币
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main()
- {
- vector<string> svect;//字符容器
-
- //输入单词
- for (vector<string>::size_type i=0;cin>>svect[i++];)
- {
- }
- //负责对单词计数
- vector<int> ivect(0);
- //进行相同单词计数
- for (vector<int>::iterator i=svect.begin();i!=svect.end();++i)
- {
- for (vector<int>::iterator j=svect.begin();j!=svect.end();++j)
- {
- //如果相等就加一
- if (svect[i]==svect[j])
- {
- ivect[i]+=1;
- }
- }
- }
- //选出最多的次数
- int max_i=ivect[0];
- vector<int>::size_type num=0;
- for(vector<int>::iterator i=ivect.begin()+1;i!=ivect.end();i++)
- {
- num=(max_i<ivect[i]) ?i:num;
- }
- //如果不是零则输出单词和个数
- if(max_i!=0)
- {
- cout<<svect[num]<<"has"<<num<<endl;
- }
- return 0;
- }
复制代码- 错误
- 1>------ 已启动生成: 项目: 测试, 配置: Debug Win32 ------
- 1>正在编译...
- 1>1.cpp
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(16) : error C2440: “初始化”: 无法从“std::_Vector_iterator<_Ty,_Alloc>”转换为“std::_Vector_iterator<_Ty,_Alloc>”
- 1> with
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1> and
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> 无构造函数可以接受源类型,或构造函数重载决策不明确
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(16) : error C2679: 二进制“!=”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(214): 可能是“bool std::_Vector_const_iterator<_Ty,_Alloc>::operator !=(const std::_Vector_const_iterator<_Ty,_Alloc> &) const”
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> 试图匹配参数列表“(std::_Vector_iterator<_Ty,_Alloc>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> and
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(18) : error C2440: “初始化”: 无法从“std::_Vector_iterator<_Ty,_Alloc>”转换为“std::_Vector_iterator<_Ty,_Alloc>”
- 1> with
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1> and
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> 无构造函数可以接受源类型,或构造函数重载决策不明确
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(18) : error C2679: 二进制“!=”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(214): 可能是“bool std::_Vector_const_iterator<_Ty,_Alloc>::operator !=(const std::_Vector_const_iterator<_Ty,_Alloc> &) const”
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> 试图匹配参数列表“(std::_Vector_iterator<_Ty,_Alloc>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> and
- 1> [
- 1> _Ty=std::string,
- 1> _Alloc=std::allocator<std::string>
- 1> ]
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(21) : error C2679: 二进制“[”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(758): 可能是“const std::basic_string<_Elem,_Traits,_Ax> &std::vector<_Ty>::operator [](unsigned int) const”
- 1> with
- 1> [
- 1> _Elem=char,
- 1> _Traits=std::char_traits<char>,
- 1> _Ax=std::allocator<char>,
- 1> _Ty=std::string
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(773): 或 “std::basic_string<_Elem,_Traits,_Ax> &std::vector<_Ty>::operator [](unsigned int)”
- 1> with
- 1> [
- 1> _Elem=char,
- 1> _Traits=std::char_traits<char>,
- 1> _Ax=std::allocator<char>,
- 1> _Ty=std::string
- 1> ]
- 1> 试图匹配参数列表“(std::vector<_Ty>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=std::string
- 1> ]
- 1> and
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(21) : error C2679: 二进制“[”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(758): 可能是“const std::basic_string<_Elem,_Traits,_Ax> &std::vector<_Ty>::operator [](unsigned int) const”
- 1> with
- 1> [
- 1> _Elem=char,
- 1> _Traits=std::char_traits<char>,
- 1> _Ax=std::allocator<char>,
- 1> _Ty=std::string
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(773): 或 “std::basic_string<_Elem,_Traits,_Ax> &std::vector<_Ty>::operator [](unsigned int)”
- 1> with
- 1> [
- 1> _Elem=char,
- 1> _Traits=std::char_traits<char>,
- 1> _Ax=std::allocator<char>,
- 1> _Ty=std::string
- 1> ]
- 1> 试图匹配参数列表“(std::vector<_Ty>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=std::string
- 1> ]
- 1> and
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(23) : error C2679: 二进制“[”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(758): 可能是“const int &std::vector<_Ty>::operator [](unsigned int) const”
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(773): 或 “int &std::vector<_Ty>::operator [](unsigned int)”
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1> 试图匹配参数列表“(std::vector<_Ty>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1>g:\资源\c\新建文件夹\win32 console application\测试\测试\1.cpp(32) : error C2679: 二进制“[”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的右操作数的运算符(或没有可接受的转换)
- 1> with
- 1> [
- 1> _Ty=int,
- 1> _Alloc=std::allocator<int>
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(758): 可能是“const int &std::vector<_Ty>::operator [](unsigned int) const”
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1> h:\新建文件夹 (1)\vc\include\vector(773): 或 “int &std::vector<_Ty>::operator [](unsigned int)”
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1> 试图匹配参数列表“(std::vector<_Ty>, std::_Vector_iterator<_Ty,_Alloc>)”时
- 1> with
- 1> [
- 1> _Ty=int
- 1> ]
- 1>生成日志保存在“file://g:\资源\c\新建文件夹\win32 console application\测试\测试\Debug\BuildLog.htm”
- 1>测试 - 8 个错误,0 个警告
- ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
复制代码
|
最佳答案
查看完整内容
一、string向量的迭代器应该也是string的
二、向量的迭代器不能作为向量的下标
三、向量不能直接输入
|