getline で区切られたテキスト ファイルを入力しようとしていますが、デバッグすると、変数の先頭に空の文字があることがわかります。
これは、たまたま各行の最初の tID 変数でのみ発生しています。デバッグすると、これが文字配列として表示されます。
[0] = '' [1] = '2' [2] = '3' [3] = '4'
関連するコードは次のとおりです。
ifstream inFile("books.txt");
if (!inFile){
cout << "File couldn't be opened." << endl;
return;
}
while(!inFile.eof()){
string tID, tTitle, tAuthor, tPublisher, tYear, tIsChecked;
getline(inFile,tID, ';');
getline(inFile,tTitle, ';');
getline(inFile,tAuthor, ';');
getline(inFile,tPublisher, ';');
getline(inFile,tYear, ';');
getline(inFile,tIsChecked, ';');
library.addBook(tID, tTitle, tAuthor, tPublisher, tYear, (tIsChecked == "0") ? false : true);
}
book.txt のいくつかの行を次に示します。
123;C++ Primer Plus; Steven Prata; SAMS; 1998;0;
234;Data Structures and Algoriths; Adam Drozdek; Course Technlogy; 2005;0;
345;The Art of Public Speaking; Steven Lucas;McGraw-Hill;2009;0;
456;The Security Risk Assessment Handbook; Douglas J. Landall;Auerbach;2006;1;