細節就看看 source code吧
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <sstream> | |
int main() | |
{ | |
vector<double> matrix; | |
//readfile | |
fstream file; | |
file.open("read.csv"); | |
string line | |
while (getline( file, line,'\n')) //讀檔讀到跳行字元 | |
{ | |
istringstream templine(line); // string 轉換成 stream | |
string data; | |
while (getline( templine, data,',')) //讀檔讀到逗號 | |
{ | |
matrix.push_back(atof(data.c_str())); //string 轉換成數字 | |
} | |
} | |
file.close(); | |
//writefile | |
file.open("write.csv"); | |
for (int i=0;i<matrix.size();i++) | |
{ | |
file << matrix[i]<<","; | |
} | |
file.close(); | |
return 0; | |
} | |