C++ 数组代码为什么不能编译?

C++ 数组代码为什么不能编译?,c++,C++,为什么这段代码没有编译。我收到的错误消息是 In function 'int main()': 10:15: error: cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&' In file included from /usr/include/c++/4.9/iostream:40:0,

为什么这段代码没有编译。我收到的错误消息是

In function 'int main()':
10:15: error: cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&'
In file included from /usr/include/c++/4.9/iostream:40:0,
                 from 1:
/usr/include/c++/4.9/istream:872:5: note: initializing argument 1 of 'std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = const char [8]]'
     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
     ^




#include <iostream>
using namespace std;
int main()
{
    int MAXTEMPS;
    int i, temp [MAXTEMPS];
    for(i=0; i< MAXTEMPS; i++) 
    {
        cout<<"Enter a Temperature:" ;
        cin>> "Temp[1]";
    }
    cout<<endl; 

    for(i=0; i<MAXTEMPS; i++)
    cout<<"Temperature "<<i<<" is" <<temp[i]<<endl; 
    return 0; 
}
原始代码:

由于某种原因,您正试图转换为文本

cin >> "Temp[1]";
去掉引号,使用正确的大小写,并使用索引变量i

首先,变量:

int MAXTEMPS;
未初始化,如原始代码所示,它需要等于5

int MAXTEMPS = 5;
其次,您无法使用字符串文本获取输入cin,并且您不习惯使用一个索引来获取输入all so temp[1],因此请执行以下操作:

cin >> temp[i];

你也应该考虑在你进入一个区块时使用选项卡来更好地理解代码中的代码

@ CESHTWAO。也许你应该简单地输入和编译原始代码,而不是你?我发现你的代码有几个错误。首先:是临时工[1],不是临时工[1]。temp[1]是一个字符串。事实上,我想你想要的是临时工[I],而不是临时工[1]。谢谢,但它仍然不起作用。现在,我没有得到任何错误消息。错误消息是6:26 MAXTEMPS在函数[-Wunitialized]中被单位化,因为MAXTEMPS未初始化,int MAXTEMPS;。你需要给它赋值,比如int MAXTEMPS=10;常量int和int的区别是什么?不允许修改常量变量,可以修改非常量变量。这将帮助您坐下来介绍一个介绍性的C++文本,其中包括很多内容。
cin >> temp[i];