前提・実現したいこと
C++でCSVで作成した3列のデータを最初の行を抜いてファイルの最後まで読み込みたいです。
例)test.csv
要素1,要素2,要素3
A1,B1,C1
A2,B2,C2
A3,B3,C3
A4,B4,C4
A5,B5,C5
・
・
・
各要素に対してstring型の変数a,b,cを用意して各行の要素を読み込み、出力したいのですが、各要素に1行すべて変数に入力されてしまいます。
例)
変数a←A1,B1,C1
また先頭行を抜く方法が解りません。
どなたかご教授お願いします。
該当のソースコード
C++
1#include <iostream> 2#include <fstream> 3#include <string> 4using namespace std; 5int main() 6{ 7string a,b,c; 8char t; 9string nm; 10ifstream ifs("test1.csv"); 11 12 13if(ifs.fail()) { 14cout << "File do not exist.\n"; 15 16} 17while(1) { 18ifs >> a >> t >> b >> t >> c; 19if(ifs.eof()) break; 20//読み込まれているかの確認 21cout<<"a "<<a<<endl; 22cout<<"b "<<b<<endl; 23cout<<"c "<<c<<endl; 24cout<<t<<endl; 25} 26}
「うまくいきません」を説明してください。
回答1件
あなたの回答
tips
プレビュー