我正在開發一個簡單的酒店預訂項目,但輸入名稱後無法打印客戶名稱和付款類型。這是我輸入的一段代碼。如何在C++中打印char數組
cout << "Please enter the customer name: " << endl;
cin >> customername1;
cin.getline(customername1,100,'\n');
fflush(stdin);
cout << "Please enter the payment type: " << endl;
cin >> paymenttype;
cin.getline(paymenttype,100,'\n');
fflush(stdin);
cout << "How many days would you like to stay: " << endl;
cin >> days;
room_income = days * 30;
count_room++ ;
count_customer1++ ;
customer_name1[single]= new char [strlen(customername1)+1];
strcpy(customer_name1[single],customername1);
payment_type[single]= new char [strlen(paymenttype)+1];
strcpy(payment_type[single],paymenttype);
cout << "Room number : " << single << endl<< endl;
cout << "Customer name : "<< customer_name1 << endl << endl;
cout << "Payment type : "<< payment_type << endl<< endl;
cout << "Number of day for accomodation :"<< days << endl<< endl;
cout << "Income for this room : "<< room_income<< endl<< endl;
顯示客戶名稱和付款類型的一些隨機數字和字母。我如何正確書寫它們?
什麼是說'customername1'的類型?爲什麼要讀兩遍? (''''和'getline') –
'new char [strlen(customername1)+1];'wooooah there!怎麼樣一個不錯的'std :: string'遊戲呢? –
'cin >> customername1;'已經讀取輸入,你爲什麼要'cin.getline(customername1,100,'\ n');''之後?? –