以后定义时候尽量把char改成string更好
但是必须在前面添加
#include <string>
// lab08.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct student
{
int num;
string name;
string sex;
double score;
}stu;
int main()
{
student*p = &stu;
stu.num = 123;
stu.name ="wang";
stu.sex = 'a46';
//只会显示最后一个字符单引号的时候
stu.score = 89.7;
cout << stu.num << 'n' << stu.name << 'n' << stu.sex << 'n' << stu.score;
return 0;
}
// lab08.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct person
{
string name;
int count;
}person2[3] = {"wang",0,"cheng",0,"xi",0};
int main()
{
string person2_name;
for (int i = 0; i < 10; i++)
{
cin >> person2_name;
for (int j = 0; j < 3; j++)
if (person2_name == person2[j].name)
person2[j].count++;
}
cout << endl;
for (int i = 0; i < 3; i++)
{
cout << person2[i].name << person2[i].count;
}
return 0;
}
// lab08.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
struct Date
{
int day;
int month;
int year;
};
struct student
{
int num;
char name[20];
char sex;
Date birthday;
double score;
}student1, student2 = {"wang","wangming",'f',5,23,2008,89.5};
int main()
{
student1 = student2;
cout << student1.num << endl;
cout << student1.name << endl;
cout << student1.sex << endl;
cout << student1.score << endl;
cout << student1.birthday.day<<'/' << student1.birthday.month<< '/' << student1.birthday.year << endl;
return 0;
}
版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!
常见资源合集和破解 fmvvvteih...