c++期望的主表达式
c++ expected primary expression before
我试着创建这个
#include <iostream>
using namespace std;
int main()
{
int right=0 , left=0;
cout << "do you go left or right?" << endl;
if (<right>) {
<you meet a troll>
}
else {
<you meet a witch>
}
}
但是我写
时会出现很多错误primary expression before);之前& lt;
你能帮帮我吗?
就像其他人说的,你真的需要做一些基础的工作。那里有很多资源,但是如果您想看到您的示例工作,下面的代码将做到这一点。我想你这里缺少的键是std::cin
,用于从键盘获得响应:
#include <iostream>
int main()
{
std::cout << "do you go left or right?" << std::endl;
std::string direction;
std::cin >> direction;
if(direction.compare("right") == 0)
{
std::cout << "you encountered a troll" << std::endl;
}
else
{
std::cout << "you encountered a witch" << std::endl;
}
return 0;
}
我重新创建了这个
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string right;
cout << "do you go left or right?" << endl;
cin >> right;
if (right == "right") {
cout << "<you meet a troll>";
}
else if (right == "left") {
cout << "<you meet a witch>";
}
}
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 提升精神:解析布尔表达式并简化为规范范式
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 概念中的cv限定符需要表达式参数列表
- 为什么constexpr的性能比正常表达式差
- Boost Accumulator_SET:期望主表达式
- 我有 3 个错误:期望一个")",期望一个表达式,long 类型的参数与 U32 类型的参数不兼容
- 预处理器定义函数期望表达式
- 错误C2057:期望的常量表达式
- 错误:')'令牌强制转换问题之前期望的主表达式
- 错误:当通过P2P通道连接两个NodeContainers时,期望主表达式在ns3中的const之前
- 试图为继承类的子类编写构造函数,猜测语法,期望的主表达式错误
- if语句中的函数:期望的错误表达式
- c++在派生类构造函数中期望的主表达式
- File.cpp:148:错误:期望的主表达式在`.不同的符号
- 在c++中期望主表达式在token之前
- c++期望的主表达式