我刚刚开始使用c++,我正在练习一些基本的代码。我要求用户输入他们的名字,这样我就可以在重复他们的名字的同时向他们问候。我该如何写这行代码呢?这是我到目前为止所知道的:
#include <iostream>
using namespace std;
int main()
{
cout << "Please enter your name: " << endl;发布于 2020-11-11 17:36:59
程序已经完成,但您还可以进一步执行以下操作:
人员数据的结构
你想要一个如何制作它的例子吗?
#include <iostream>
#include <string.h>
struct People { // Making a struct
char name[20]; // to save the name
float height; // to save the height of the person
} person; //Obj name (the name of the struct user)
using namespace std;
int main()
{
// You have to name your structure to use it in the main
cout << "Hi enter your name: " << endl;
cin >> person.name; // You are getting name from user's input
cout << "Hello, " << person.name ; // The name is saved and reused
cout << ", How tall are you? \n"; // You can get also decimals numbers
cin >> person.height; // Gettin' the height
cout <<"\n\nSo you are "<<person.name<<" and "<<person.height<<" tall!"; //resuming
}结构是什么?
根据Wikipedia的说法,
C编程语言中的结构是复合数据类型(或记录)声明,在内存块中的一个名称下定义了变量的物理分组列表,允许通过单个指针或通过返回相同地址的结构声明名称来访问不同的变量。struct数据类型可以包含其他数据类型,因此可用于混合数据类型记录,如硬盘驱动器目录项或其他混合类型记录。
举个例子:
struct [structure tag] { struct Books {
member definition; char title[50];
member definition; char author[50];
... ...
member definition; char subject[100];
} [one or more structure variables]; } one_book;如果这个答案让你满意,那么就把它标记为已解决。
https://stackoverflow.com/questions/64781619
复制相似问题