中国有唱功的女歌手:请问'<<' : illegal, right operand has type 'char [10]'什么意思?
来源:百度文库 编辑:高考问答 时间:2024/07/07 08:56:39
#include <stdio.h>
#include <iostream.h>
void main()
{
int i=1,iSum=0;
short shCounter=128;
long lgResult=i+shCounter;
cout<<"lgResult="<<lgResult<<endl;
}
错误是D:\VC练习\Cpp002.c(9) : error C2065: 'cout' : undeclared identifier
D:\VC练习\Cpp002.c(9) : error C2297: '<<' : illegal, right operand has type 'char [10]'
D:\VC练习\Cpp002.c(9) : error C2065: 'endl' : undeclared identifier
#include <iostream.h>
void main()
{
int i=1,iSum=0;
short shCounter=128;
long lgResult=i+shCounter;
cout<<"lgResult="<<lgResult<<endl;
}
错误是D:\VC练习\Cpp002.c(9) : error C2065: 'cout' : undeclared identifier
D:\VC练习\Cpp002.c(9) : error C2297: '<<' : illegal, right operand has type 'char [10]'
D:\VC练习\Cpp002.c(9) : error C2065: 'endl' : undeclared identifier
用cout,应是C++程序,原程序名要用Cpp002.cpp,不应当用Cpp002.c
'cout' : undeclared identifier
说cout是未声明过的标识符
'<<' : illegal, right operand has type 'char [10]'
编译理解为左移运算,说左移运算是非法的,因为右边的运算用的数是char型.(unsigned char型才可以).
'endl' : undeclared identifier
说endl是未声明过的标识符
-----------------------
出错原因是C++程序,原程序名要用Cpp002.cpp
#include <stdio.h> 是C程序的头文件,可以不要.
#include <iostream>
using namespace std;
int main()
{
int i=1,iSum=0;
short shCounter=128;
long lgResult=i+shCounter;
cout<<"lgResult="<<lgResult<<endl;
return 0;
}
经VC++2005调试成功