2012-04-04 25 views
0

私は、駐車料金を計算して印刷するプログラムを作成しています。私はユーザーが入力するためにget.lineを使用していますが、 "find"を使って行を区切りますか?C++プログラミング

#include <iostream> 
#include <fstream> 
#include <iomanip> 
#include <string> 
#include <cmath> 
using namespace std; 
int main() 
{ 
string enter_date; 
string enter_time; 
string exit_date; 
string exit_time; 
int calculatecharge; 
int num; 

cout << "Please enter the date and time the car is entering "<< endl 
<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl; 
getline (cin,enter_date); 
getline (cin,enter_time); 
cout<< "Please enter the date and time the car is exiting "<< endl 
<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl; 
getline (cin,exit_date); 
getline (cin,exit_time); 

find(' ') 


cout<<"Parking fee due: "<< num << endl; 
return 0; 
} 
+0

私はあなたのフォーマットを修正しました。あなたのスペルや句読点を修正してください。あなたの質問をもっと慎重に書いてください。*あなたがこの質問を投稿して10秒以上過ごしたことを*表示してください。 – Beta

+0

getlineを使用すると入力行が得られますので、ユーザーが "2012/4/3 11:59"と入力すると、enter_date文字列にその行が入ります。あなたがYY/MM/DDフォーマットを期待しているならば、それを期待して読んでみてはいかがですか?たとえば、std :: cin >> yearStr >> dummyChar >> monthStr >> dummyChar >> dayStr; – dchhetri

+0

私はC++で1ヶ月しか作業していません。私はまだプログラミングのすべての機能とスタイルを学びたいと思っています。私はインストラクターの助けを借りることができません(彼は助けていません)。私はこれを自分で学習しています。私のプログラムを助けてくれてありがとう。 – user1311854

答えて

0

getline()を2回使用する場合は、次のコードを試してください。

getline (cin, enter_date, ' '); 
getline (cin, enter_time);