我在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;
}
答案 0 :(得分:1)
你知道你在if语句中做作业吗?在C ++中将等同写为==
。另外,为什么vsize?向量有自己的方法来获取大小,in.size()
会给你这个。
答案 1 :(得分:0)
我希望能够在我走得更远之前编译它...... 很好!
但是你应该阅读错误和警告信息,它们通常有助于理解问题及解决问题的方法(以下使用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);
我只针对每个错误采用了一个示例,您应该能够修复重复项: - )