c++ - 如何将单词放入var
问题描述
我想设置一个向“客户”询问个人信息的程序,并且此代码需要将姓名和姓氏存储在一个包含 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”。谢谢你的帮助
解决方案
您必须更改nom
和prenom
中的数据类型struct info
。类型int
代表数字。字符串(或单词)std::string
在 C++ 中表示为:
struct info {
std::string nom;
std::string prenom;
};
如果我对您的代码进行更改并输入我的姓名,我会在输出中看到它。
推荐阅读
- ionic-framework - Ionic 4:更改输入字段的填充
- android - 需要帮助发送表单数据(android)
- c# - 如何在插入前获取自动生成的 ID?
- riak - 我们可以创建超过 2 个 riak 集群吗
- node.js - TypeError: locations.join is not a function in google-distance-matrix
- jquery - Chrome 扩展弹出 Dom 更改未更新
- python - 为什么 \b 在 python3 中不起作用?
- dataframe - dataframe to_datetime not reading dates correctly
- javascript - How to search for a string in array of arrays using javascript function
- javascript - Babel showing unexpected error, couldn't find the solution