以下C++程序运行出现 excepted initializer beforebool operatorr

您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
c++上机实验报告.doc 104页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
上机实验报告
你可能关注的文档:
··········
··········
实验1 熟悉上机环境及C++基础实验
1.实验目的和要求
(1)熟悉上机环境,了解Visual C++6.0集成开发环境、掌握源程序编辑、程序调试、查看变量、程序运行;
(2)熟悉C++的程序结构,掌握main函数、保留字、变量及变量定义、输入与输出流等概念;
(3)熟悉类与类对象的定义、类成员的调用。
2.实验内容
任务1:程序调试
#include&iostream.h&
int main()
cout&&&您好!浙江大学欢迎您,愿您喜欢C++的输入输出。&;
cout&&2008;
cout&&&\n&;
cout&&20.1;
cout&&&I am&&&&years old student.&;
char name[30];
cout&&&please give your name:&;
cout&&&please tell me how are you?&;
cout&&&Your name is&&&name&&
cout&&&you are&&&age&&&years old.&;
思考1:1)在程序中任何一行少一个“;”符号,有什么提示?
error C2146: syntax error : missing ';' before identifier 'cout'
2)删除这一行,编译后有什么错误提示。
error C2065: 'age' : undeclared identifier
思考2:1)C++中的注解有哪些?
C++注解形式有两种:单行注解(//)以及多行注解(/*….*/)
2)应用输入输出流应包含什么库?
输入输出流库 iostream.h
3)定义变量有什么含义?
给变量分配存储空间
4)常用变量有哪些基本类型?
任务2:程序调试
在实验1的源程序基础上,作以下程序的调试,并回答相关问题。
(1)用单行注释符”//”注解预处理命令,编译程序有什么提示?
error C2065: 'cout' : undeclared identifier
error C2297: '&&' : illegal, right operand has type 'char [46]'
warning C4552: '&&' : op expected operator with side-effect
error C2297: '&&' : illegal, right operand has type 'char [2]'
error C2296: '&&' : illegal, left operand has type 'const double'
error C2297: '&&' : illegal, right operand has type 'const double'
error C2065: 'endl' : undeclared identifier
warning C4552: '&&' : op expected operator with side-effect
error C2297: '&&' : illegal, right operand has type 'char [5]'
error C2297: '&&' : illegal, right operand has type 'char [23]'
error C2065: 'cin' : undeclared identifier
error C2297: '&&' : illegal, right operand has type 'char [30]'
error C2297: '&&' : illegal
正在加载中,请稍后...c++ - expected initializer before ‘&’ token - Stack Overflow
to customize your list.
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I wrote a simple example which came from the book "The C++ Programming.Language.4th.Edition"
#include &ostream&
struct Entry{
ostream& operator&&(ostream& os, const Entry& e){
return os && "{\"" && e.name && "\"," && e.number && "}";
int main()
a.name = "Alan";
a.number = "12345";
The g++ returned an error message while compiling
error: expected initializer before ‘&’ token
ps: the & token mentioned above belongs to the ostream& operator
could anyone give a clue ?
closed as off-topic by , , , ,
This question appears to be off-topic. The users who voted to close gave this specific reason:&This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting
before posting.& & dasblinkenlight, WhozCraig, Amarnath Balasubramanian, Shoe, Yu Hao If this question can be reworded to fit the rules in the , please .
You have four main errors:
First of all you are missing semicolon after the struct declaration. After each, class or struct declarations you need to put a ;.
Secondly ostream is not an identifier, you probably meant to use std::ostream. ostream, in the &ostream& standard header, lives in the std namespace.
Thirdly you are missing the std::string header, and you should refer to the string class with the std:: prefix.
Finally number is of type int, not of type const char* like the literal "12345" is. You probably meant to write: a.number = 12345;.
After all these fixes, your program will look like this:
#include &ostream&
#include &string&
struct Entry{
std::ostream& operator&&(std::ostream& os, const Entry& e){
return os && "{\"" && e.name && "\"," && e.number && "}";
int main()
a.name = "Alan";
a.number = 12345;
56.7k23109197
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledc++ error: expected initializer before ‘*’ token_百度知道
c++ error: expected initializer before ‘*’ token
struct patron{ char name[16];
}patron *list = new patron[10];int i,j=0,totalPeople,patrons = 0,grandpatrons = 0;
我有更好的答案求助知道网友
你的 struct 语句后面没有“;”
patron **list = new patron[10];
struct patron{ char name[16];
};patron *list = new patron[10];int i,j=0,totalPeople,patrons = 0,grandpatrons = 0;朋友,请【采纳答案】,您的采纳是我答题的动力,如果没有明白,请追问。谢谢。
本回答被提问者和网友采纳
1条折叠回答
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。当前位置:&&技术问答>
编译JNI.h报大量错
&&&&来源:&互联网& 发布时间:
&&&&本文导语:&
大家好,我想用jni给我的C++包壳,以便他用JAVA程序调用
我编译的时候发现jni.h报出了大量的错误
我用gcc -c jni.h
In file included from jni.h:27:
jni_md.h:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__at...
大家好,我想用jni给我的C++包壳,以便他用JAVA程序调用
我编译的时候发现jni.h报出了大量的错误
我用gcc -c jni.h
In file included from jni.h:27:
jni_md.h:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jlong’
jni.h:108: error: expected specifier-qualifier-list before ‘jlong’
jni.h:202: error: expected ‘)’ before ‘*’ token
jni.h:204: error: expected ‘;’ before ‘jclass’
jni.h:1877: error: expected ‘)’ before ‘*’ token
jni.h:1879: error: expected ‘;’ before ‘jint’
jni.h: In function ‘__declspec’:
jni.h:1917: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JNI_GetDefaultJavaVMInitArgs’
jni.h:1919: error: expected declaration specifiers before ‘__declspec’
jni.h:1922: error: expected declaration specifiers before ‘__declspec’
jni.h:1926: error: expected declaration specifiers before ‘__declspec’
jni.h:1929: error: expected declaration specifiers before ‘__declspec’
jni.h:1930: error: expected ‘{’ at end of input
-----------------------
如果我要是用g++ 编译,返回的错误更多?请问这是为什么
应该使用-I把jni的路径加入gcc的头文件搜索路径。
不过你怎么直接编译起头文件来了?
缺少很多头文件的, 用-I加上头文件路径。
jni.h肯定包含了其他系统头文件或者自定义文件你没有包含。
您可能感兴趣的文章:
本站(WWW.169IT.COM)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。本站(WWW.169IT.COM)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
相关文章推荐
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!
(C)9IT.COM,E-mail:www_169it_com#163.com(请将#改为@)

我要回帖

更多关于 operator new 的文章

 

随机推荐