c++输入客户信息
时间: 2023-07-19 11:14:29 浏览: 40
您可以使用如下的C++代码来输入客户信息:
```c++
#include <iostream>
#include <string>
using namespace std;
struct customer {
string name;
int age;
string address;
};
int main() {
customer c;
cout << "Enter customer name: ";
getline(cin, c.name);
cout << "Enter customer age: ";
cin >> c.age;
cin.ignore(); // 忽略之前输入留下的换行符
cout << "Enter customer address: ";
getline(cin, c.address);
cout << "\nCustomer information:" << endl;
cout << "Name: " << c.name << endl;
cout << "Age: " << c.age << endl;
cout << "Address: " << c.address << endl;
return 0;
}
```
这段代码使用了一个 `struct` 结构体来存储客户信息,并使用 `getline()` 函数来输入字符串类型的数据。需要注意的是,在输入 `age` 的时候,需要使用 `cin.ignore()` 函数来忽略之前输入留下的换行符。