如何将一个单词放入变量中

How to put a word into a var

本文关键字:单词放 一个 变量      更新时间:2024-09-23

我想设置一个程序,向一个";客户";,这个代码需要将一个名字和一个姓氏存储在一个与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的含义是名字(我是法国人(这不起作用。。。。为什么?确切地说,我别无选择,只能使用"结构"来存储";nom";以及";婚前协议";。感谢您的帮助

您必须更改struct infonomprenom的数据类型。类型int表示数字。字符串(或单词(在C++中用std::string表示:

struct info {
std::string nom;
std::string prenom;
};

如果我对你的代码进行了更改,并输入了我的名字,我会在输出中看到它。