そのため、ファイルの読み取りと書き込みを処理するプログラムを作成しています。テキスト ファイルの一部の行には複数の要素が含まれている可能性があるため、getline() 関数を使用します。今まで getline で問題が発生したことはありません。これが私が得たものです。
テキスト ファイルは次のようになります。
John Smith // Client name
1234 Hollow Lane, Chicago, IL // Address
123-45-6789 // SSN
Walmart // Employer
58000 // Income
2 // Number of accounts the client has
1111 // Account Number
2222 // Account Number
そして、次のようなコード:
ifstream inFile("ClientInfo.txt");
if(inFile.fail())
{
cout << "Problem opening file.";
}
else
{
string name, address, ssn, employer;
double income;
int numOfAccount;
getline(inFile, name);
getline(inFile, address);
// I'll stop here because I know this is where it fails.
このコードをデバッグしたところ、name == "John Smith" ではなく、name == "John"、Address == "Smith" などであることがわかりました。私は何か間違ったことをしていますか?どんな助けでも大歓迎です。