(参考:https://www.runoob.com/cplusplus/cpp-data-structures.html)
标准输入流:
cin >> name >> bird;
<iomanip> 常见的操作符:setw(int w) // setprecision(int p) 有效数字而不是小数点后面的位数
#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
double name,bird;
cin >> name >> bird;
cout.precision(1);
cout << name << endl;
cout.precision(2);
cout << bird << endl;
return 0;
}
结构体类型:
//访问结构成员
//声明一个结构类型 Books
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
};
Books Book1;
cout << Book1.author << endl; //成员访问运算符
//函数作为函数参数
void printBook( struct Books book );
Books Book1;
void printBook( struct Books book )
{
cout << "书标题 : " << book.title <<endl;
}
//指向结构的指针 ->
void printBook( struct Books *book );
printBook( &Book1 );
void printBook( struct Books *book )
{
cout << "书标题 : " << book->title <<endl;
}
//typedef 关键字
typedef struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
}Books;
//现在可以直接使用 Books 来定义 Books 类型的变量,而不需要使用 struct 关键字
Books Book1, Book2;
//另一个例子
typedef long int *pint32;
pint32 x, y, z;
//x, y 和 z 都是指向长整型 long int 的指针