在C ++中从CSV文件拆分文本行和列

时间:2016-09-26 23:18:34

标签: c++ string csv

所以我需要读取这两个csv文件,它们每个都有几列用空格分隔的文本。如何在不使用向量或数组的情况下将这些行拆分为标记?我是用c ++做的,无法找到任何帮助。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

   int main() {
      string line;
       ifstream myfile ("elect12.csv");
       if (myfile.is_open ())
        {
         cout << endl << "popular results " << endl;
         while (getline (myfile, line))
         {
          cout << line << endl;
         }
        myfile.close();
       }
       else cout << "unable to open";

      string line1;
       ifstream myfile1 ("ev10.csv");
       if (myfile1.is_open ())
        {
         cout << endl << "electoral votes per state" << endl;
         while (getline (myfile1, line1))
         {
          cout << line1 << endl;
         }
        myfile1.close();
       }
       else cout << "unable to open";

return 0;
}

the image included is what the output looks like right now

0 个答案:

没有答案