没有运算符与这些操作数 C++ 匹配
no operator matches these operands c++
my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str1[1000000];
char newString[1000][1000];
int i,j,ctr;
cout <<" nn Split string by space into words :"<< endl;
cout << "---------------------------------------n";
cout << " Input a string : ";
cin >> str1 >> sizeof(str1) >> stdin;
j=0; ctr=0;
for(i=0;i<=(strlen(str1));i++)
{
// if space or NULL found, assign NULL into newString[ctr]
if(str1[i]==' '||str1[i]==' ')
{
newString[ctr][j]=' ';
ctr++; //for next word
j=0; //for next word, init index to 0
}
else
{
newString[ctr][j]=str1[i];
j++;
}
}
cout << "n Strings or words after split by space are :n";
for(i=0;i < ctr;i++)
cout << newString[i];
return 0;
}
错误语句:
错误1 错误 C2679:二进制">>":未找到需要 类型为"无符号 int"的右操作数(或者没有可接受的操作数 转换( c:\users\ayah atiyeh\documents\Visual Studio 2012\项目\控制台应用程序1\控制台应用程序1\源.cpp 14 3 智能感知:没有运算符">>"与这些操作数匹配 操作数类型为:std::basic_istream>>> unsigned int c:\Users\Ayah Atiyeh\Documents\Visual Studio 2012\项目\控制台应用程序1\控制台应用程序1\源.cpp 14
你需要这样做:
cout << " Input a string : ";
cin >> str1;
而不是:
cout << " Input a string : ";
cin >> str1 >> sizeof(str1) >> stdin;
问题是,>>运算符用于将输入定向到其右侧的变量。而且您没有在第二个>>的右侧给出一个变量,sizeof(str1( 是一个函数,它返回一个数字。当编译器看到一个数字代替变量时,它会给你这个错误。
更改
char str1[1000000];
自
std::string str1;
和
cin >> str1 >> sizeof(str1) >> stdin;
自
std::cin >> str1;
顺便说一句 - 删除行using namespace std;
然后行
for(i=0;i<=(strlen(str1));i++)
应该是
for(i=0;i<str1.length();i++)
cin >> str1 >> sizeof(str1) >> stdin;
在此输入语句的第二部分中,您尝试读入右值(sizeof(str1)
是编译时常量,是右值(。你不应该那样做。读取某些内容stdin
也是一个危险的操作,因为它的类型是FILE*
,这可能会对进一步的输入操作产生负面影响。
相关文章:
- 控制允许动态运行c++的并发操作数
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 错误 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' 的操作数
- 非法,左操作数具有类型 'DWORD [29]'