没有运算符">>"与这些操作数匹配
No operator ">>" matches these operands
我对这个问题做了一些挖掘,发现其他人与我有相似但不相同的错误。我的两个主要理论是,我错过了一些明显的东西,或者我破坏了Visual Studio。代码运行如下:
// ConsoleApplication5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
int child;
int adult;
int costs;
string movie;
int profits;
std::cout >> "What is the name of the movie? ";
std::getline(cin, movie);
std::cout >> "How many kids went to the movie? ";
std::cin << child;
std::cout >> "how many adults went to the movie? ";
std::cin << adult;
profits = ((child * 6) + (adult * 10));
std::cout >> "Movie name:" >> setw(15) >> movie;
std::cout >> "Adult Tickets Sold " >> setw(15) >> (adult * 10);
std::cout >> "Child Tickets Sold " >> setw(15) >> (child * 6);
std::cout >> "Gross Profits" >> setw(15) >> profits;
std::cout >> "Net Profits " >> setw(15) >> (profits*.2);
std::cout >> "Amount paid to distributor " >> setw(15) >> (profits - (profits*.2));
return 0;
}
>>
和<<
的每个实例都带有红色下划线,并带有错误消息:
- 没有运算符">>"与这些操作数匹配
- 标识符"setw"未定义
我很确定我做了一些明显和错误的事情,但我一辈子都找不到它。
你得到了>>
,<<
颠倒了。 <<
是为了std::cout
,>>
是为了std::cin
。你正在做相反的事情。您还需要包含iomanip
用于std::setw
.
<<
是一个流插入运算符,它与cout
的ostream
对象一起使用。 >>
是一个流提取运算符,它与对象cin
一起使用并istream
。在您的程序中,您已经清楚地交换了它们的位置。修复它,然后一切都会顺利进行。
此外,您已经编写了语句,using namespace std
,则无需再次使用指定命名空间。我的意思是要么将std::cout
(和所有其他类似的行(更改为cout
,要么只是删除行using namespace std;
.但是,后者是更好的选择。
相关文章:
- 控制允许动态运行c++的并发操作数
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- EASTL矢量<向量<int>>连续的
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C++ 带有向量的 IF 计算操作数
- 是否所有C++运算符都接受操作数?
- 一元*运算符的操作数是否期望一个 prvalue
- 与'operator='不匹配(操作数类型'String'且"void")
- 不正确的操作数类型 MSVC
- C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 我的运算符重载是否有效<<(流插入)左操作数不是 ostream
- 没有运算符"="与这些操作数匹配,JUCE 窗口演示应用程序
- 如果我在指针中使用 ++ 操作数,我的值就会出错
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- C2679 二进制"<<":未找到采用右操作数类型的运算符
- CPP 运算符重载操作数位置 [] 与 ==
- int* 和 int[] 类型对二进制运算符 + 的操作数无效
- 错误:二进制'operator*' 'float'和'float[0]'类型的操作数无效
- 运算符'<'不能应用于类型 'string' 和 'string' 的操作数