统计
  • 建站日期:2021-03-10
  • 文章总数:518 篇
  • 评论总数:151 条
  • 分类总数:32 个
  • 最后更新:4月20日
文章 未分类

指针和结构体

梦幻书涯
首页 未分类 正文

 

以后定义时候尽量把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;
}

 

版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。
版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!

这篇文章最后更新于2018-12-19,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
大学C++程序设计教程期末复习重点
« 上一篇
计算机导论
下一篇 »

发表评论

HI ! 请登录
注册会员,享受下载全站资源特权。
Array

日历

热门文章