を印刷することができます。ここに私がタイプしたコードがあります。は、どのように私は、単純なホテルreservsationプロジェクトに取り組んでいますが、私は自分の名前を入力した後、顧客の名前と支払いの種類を印刷することができませんでした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'の種類は何です...コメントをたどるとstd :: stringとベクターに見えますか?なぜそれを2回読むのですか? ( '' ''と '' getline') –
'新しいchar [strlen(customername1)+1];' wooooah there!代わりに 'std :: string'のいいゲームをどうですか? –
'cin >> customername1;'はすでに入力を読み込みます、なぜあなたは 'cin.getline(customername1,100、 '\ n');'それ以降ですか? –