【发布时间】:2020-11-11 21:39:18
【问题描述】:
我想设置一个向“客户”询问个人信息的程序,并且此代码需要将姓名和姓氏存储在包含 var 的结构中。 但在输出中它显示了一个数字。
#include <iostream>
using namespace std;
//DECLARATIONS
struct dates {
int emb_date;
int post_date;
};
struct info {
int nom;
int prenom;
};
void saisie_info() {
info identite;
cout << "Veuillez indiquer votre prenom : " << endl;
cin >> identite.prenom;
cout << "Veuiller maintenant insiquer votre nom : " << endl;
cin >> identite.nom;
cout << identite.prenom << " " << identite.nom << endl;
}
int main()
{
saisie_info();
}
如您所见:prenom 表示姓氏,nom 表示姓名(我是法国人) 而且那行不通.... 为什么 ? 我准确地说我没有其他选择来使用'''struct'''来存储“nom”和“prenom”。 感谢您的帮助
【问题讨论】:
-
“不工作”是什么意思?代码有什么作用?它应该怎么做?什么是输入、输出、预期输出?
-
代码“正常”。我的意思是对于名为 46303 和 sursame 5818 的人来说没有问题。为什么
prenom和nom是整数? -
你熟悉
strings吗? tutorialspoint.com/cplusplus/cpp_strings.htm -
"他的代码需要将姓名和姓氏存储在一个包含所有变量的结构中。但在输出中它显示了一个数字。" 如果您需要存储一个名字或姓氏,你为什么要把它们读成
int,它代表integer? -
您是否尝试reading a good C++ textbook 来了解 C++ 中存在哪些变量类型以及如何使用它们?