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

标签 c++ cin

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/

相关文章:

c++ - 我如何存储数组以在 C++ 中排队

c++ - 运算符重载 >> 和私有(private)成员

c++ - 无法创建一个类的多个实例?

c++ - 分别创建目标文件然后在 Makefile 中将它们链接在一起的目的是什么?

c++ - 在 C++ 中将 double 转换为 int 丢失 1

c++ - C++ 中字符数组与整数数组的指针

c++ - 运行 while 循环直到收到特定输入,但如果没有收到 c++ 则重新运行

c++ - 输出冗余

c++ - 如何确保 cin 正确打开文件?

c++ - 在 C++ 中使用 scanf() 和 printf() 的意外输出