Re: [問題] 將csv黨案讀入二維陣列中

看板C_and_CPP (C/C++)作者 (蒼穹之下任我行)時間10年前 (2015/09/10 10:31), 10年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《pipited07 (天啊完全不知道取什麼)》之銘言: : 小弟是c++新手希望別嫌問題太簡單@@ : 開發平台(Platform): visual studio 2013 c++ : 資料: excel檔案轉存的csv檔案 : 問題(Question):如果我有一筆確定行列的二維資料要怎麼寫能讓他存進陣列 : 好讓我能直接輸出呢? 確定行列是二維資料,就直接寫死讀法... #include <iostream> #include <fstream> #include <string> using namespace std; int main(int argc, char const *argv[]) { string filename = "data.csv"; ifstream input(filename.c_str()); string line; while(!input.eof()) { // 讀一整行 get_line(input, line); if(!input.eof()) { // 找到逗號的位置 int comma_pos = line.find(','); // 用string的函式抓出逗號分隔的sub string string x = line.substr(0, comma_pos); string y = line.substr(comma_pos+1); // x跟y就是那一行的數值了 cout << x << " : " << y << endl; } } input.close(); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.244.41.5 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1441852316.A.7A3.html ※ 編輯: yichen (60.244.41.5), 09/10/2015 10:57:26

09/11 01:18, , 1F
感恩抽空回覆 真是太感謝了~
09/11 01:18, 1F
文章代碼(AID): #1LyEkSUZ (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1LyEkSUZ (C_and_CPP)