私の問題は、テキスト ファイルから char、string、int の順に入力しようとしていることです。getline() を使用して入力する方法は知っていますが、get line() 関数を使用した後、文字列に続く残りの整数を入力するオプションがなくなりました。私の質問は、どのように char を入力し、次に文字列 (スペースを含む) に続いて 3 つの int を入力できますか?
data.txt は次のようになります
a New York 5 7 9
b Virginia 10 2 5
c Los Angeles 25 15 6
これが私のコードです:
int main()
{
string city;
double price;
int amt1, amt2, amt3;
char orderStatus;
ifstream warehouse;
ofstream output;
warehouse.open("data.txt");
output.open("dataOut.txt");
while (warehouse.good())
{
warehouse >> orderStatus;
output << orderStatus << "\t";
getline(warehouse, city, '\t');
//warehouse >> city;
output << city << endl;
//warehouse >> amt1;
//output << amt1 << "\t";
//warehouse >> amt2;
//output << amt2 << "\t";
//warehouse >> amt3;
//output << amt3;
}
warehouse.close();
output.close();
return 0;
}
大変お世話になりました。