与操作员不匹配>>问题
No match for operator>> issue
我在unix终端中运行这个程序,但是当我试图编译它时,它给出了一个巨大的问题列表,但是我认为问题是部分说不匹配操作符>>。我意识到这个程序缺失了很多,它还没有接近完整,我希望能够在我走得更远之前编译它。我不知道是什么原因导致这个错误,希望能得到帮助。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int ui = 0 ;
vector<string> in;
string temp = "0";
int vsize = 0;
while(ui != 5)
{
cout << "1. Read" << endl;
cout << "2. Print" << endl;
cout << "3. Sort" << endl;
cout << "4. Search" << endl;
cout << "5. Quit" << endl;
std::cin >> ui >> std::endl;
if(ui = 1)
{
while(temp != "q")
{
std::cout << "Enter the next element (Enter 'q' to stop):" << std::endl;
std::cin >> temp >> std::endl;
in.pushback(temp);
vsize++;
}
}
if(ui = 2)
{
std::cout << "Sequence: ";
for (int i = 0; i < vsize; i++)
{
cout << in[i];
}
std::cout << std::endl;
}
if(ui = 3)
{
}
}
return 0;
}
你知道你在if语句中做赋值吗?等式在c++中写为==
。还有,为什么是vsize?向量有它自己的方法来获取大小,in.size()
会给你。
我希望能够在我走得更远之前编译它…好了!
但是你应该读取的错误和警告消息,它们通常有助于理解问题和解决问题的方法(以下使用CLang输出):
ess.cpp:21:31: error: reference to overloaded function could not be resolved;
did you mean to call it?
std::cin >> ui >> std::endl;
你试图提取的东西到std::endl
是没有意义的。只写std::cin >> ui;
ess.cpp:23:19: warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
if(ui = 1)
ui = 1
是赋值。相等性检验应为if (ui == 1)
ess.cpp:29:32: error: no member named 'pushback' in
'std::__1::vector<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >'; did you
mean 'push_back'?
in.pushback(temp);
…我也认为你指的是in.push_back(temp);
我只拿了一个例子,每个错误,你应该能够修复重复:-)
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题