当前位置:编程学习 > VC++ >>

vc++ 程序出现错误

// li7_5_4.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream" #include "string" using namespace std; struct Student {int num; string name; float score[3]; }stu={123456,"lifung",67.5,89,78.5}; int main(int argc, char* argv[]) {void print(Student &); print (stu); return 0; } void print (Student &stud) {cout <<stud.num <<" "<<stud.name <<" "<<stud.score[0]<<" "<<stud.score[1]<<" "stud.score[2]<<endl; } -------------------Configuration: li7_5_4 - Win32 Debug-------------------- Compiling... li7_5_4.cpp D:\c++\li7_5_4\li7_5_4.cpp(12) : error C2552: 'stu' : non-aggregates cannot be initialized with initializer list D:\c++\li7_5_4\li7_5_4.cpp(19) : error C2146: syntax error : missing ';' before identifier 'stud' D:\c++\li7_5_4\li7_5_4.cpp(19) : error C2563: mismatch in formal parameter list D:\c++\li7_5_4\li7_5_4.cpp(19) : error C2568: '<<' : unable to resolve function overload could be 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)' e:\vc98\include\ostream(377) : see declaration of 'endl' or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)' e:\vc98\include\ostream(372) : see declaration of 'endl' or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)' e:\vc98\include\ostream(367) : see declaration of 'endl' Error executing cl.exe. li7_5_4.obj - 4 error(s), 0 warning(s)
追问:那么请问这个结构体定义出来还有什么用;;;;不是多此一举了嘛、、我想要的就是定义结构体然后直接对它初始化;;然后直接输出;;;;
答案:#include "iostream"
#include "string"
using namespace std;
struct Student
{
	int num;
	string name;
	float score[3];
};

void print (Student &stud)
{
	//cout <<stud.num <<" "<<stud.name <<" "<<stud.score[0]<<" "<<stud.score[1]<<" "stud.score[2]<<endl;
	cout <<stud.num<<" "<<stud.name <<" "<<stud.score[0]<<" "<<stud.score[1]<<" "<<stud.score[2]<<endl;
}

int main(int argc, char* argv[])
{
	Student stu;
	stu.num = 123456;
	stu.name = "lifung";
	stu.score[0] = 67.5;
	stu.score[1] = 89;
	stu.score[2] = 78.5;

	print(stu);
	return 0;
} 
//编译通过,记得给分哦
其他:vc++ 程序出现错误



更新快 而且多IZG。 http://cang.zhaoxi.net/upsb245 。JQF觉得不错,要给我采纳哦





靖萱走了,我和你再带走书晴,曾家就只剩下三个老人了!你要
8q





们从小灌输她的又是什么样的教育?为了一个石头建筑物,一个女人要不就苦苦的守,




 不能进行list赋值,需要创建对象后对成员进行逐个赋值

上一个:想学VC应该怎么入门
下一个:用vc++6.0编译程序时正确,运行时显示应用程序异常怎么回事

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,