gpt4 book ai didi

c++ - 没有运算符匹配这些操作数 C++

转载 作者:行者123 更新时间:2023-11-27 23:49:42 25 4
gpt4 key购买 nike

my code:
#include <iostream>
#include <string>
using namespace std;

int main()
{
char str1[1000000];
char newString[1000][1000];
int i,j,ctr;
cout <<" \n\n 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]=='\0')
{
newString[ctr][j]='\0';
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;
}

错误说明:

Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'unsigned int' (or there is no acceptable conversion) c:\users\ayah atiyeh\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\source.cpp 14 3 IntelliSense: no operator ">>" matches these operands operand types are: std::basic_istream> >> unsigned int c:\Users\Ayah Atiyeh\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Source.cpp 14

最佳答案

你需要这样做:

cout << " Input  a string : ";
cin >> str1;

代替:

cout << " Input  a string : ";
cin >> str1 >> sizeof(str1) >> stdin;

事实是,>> 运算符用于将输入定向到它右侧的变量。你没有在第二个 >> 的右边给出一个变量,sizeof(str1) 是一个函数,它返回一个数字。当编译器看到一个数字而不是一个变量时,它会给你那个错误。

关于c++ - 没有运算符匹配这些操作数 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com