看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《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
pipited07: 感恩抽空回覆 真是太感謝了~ 09/11 01:18