#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <sstream>
using namespace std;
struct person
{
int age;
string name[20], dob[20], pob[20], gender[7];
};
int main()
{
person person[10];
cout << "Please enter your name, date of birth, place of birth, gender, and age, separated by a space.\nFor example, John 1/15/1994 Maine Male 20: ";
scanf("%s %s %s %s %d", &person[0].name, &person[0].dob, &person[0].pob, &person[0].gender, &person[0].age);
printf("%s %s %s %s %d", &person[0].name, &person[0].dob, &person[0].pob, &person[0].gender, &person[0].age);
return 0;
}
我嘗試掃描並打印用戶的年齡,但它給了我2749536的person.age
值。這是爲什麼?爲什麼我不能scanf和printf一個整數?
使用'%f'浮點數。或者像'int age'一樣定義年齡;' –
使用'cin'和'cout'(你在開始時就已經做過一次),如果你使用的C++特性不能用在C('iostream','cout','using namespace'等) –
我打算寫int。但它仍然不起作用。 – johnny880