从第x列到y列以及从第1行到第2行提取csv数据c ++ [英] Extract csv data from column x to column y, and from row 1 to row 2 c++

查看:75
本文介绍了从第x列到y列以及从第1行到第2行提取csv数据c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.csv文件,比方说,有1000行和1200列.

I have a .csv file, let's say, 1000 rows and 1200 columns.

如何从所需的列(例如67)中提取数据到另一列(例如890)中.并同时从一行假设9 到另一行假设789 ,然后使用C ++将数据导出为新的csv文件?

How to extract the data from desired column, let's say 67, to another column, let's say 890. And at the same time from a row, let's say 9, to another row, let's say 789, then export the data as new csv file with C++?

我仍然是初学者,但熟悉for或while循环,并且可以读取文件.

I am still beginner but familiar with for or while loop, and I can read a file.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main() {

    ifstream csvFile;

    csvFile.open("../example.csv"); 

    if (csvFile.is_open())
        {

    string line;

    while(getline(csvFile, line))
    {

    //what to do here

    }
        }

    else {

    cout << "Sorry, the file could not be openend." <<endl;

    return -1;

    }

    csvFile.close();

    return 0;

    }

修改例如源csv文件:

a,1,11,111
b,2,22,222
c,3,33,333
d,4,44,444

假设我们只希望从第2列到第3列,从第2行到第3列,那么结果是一个新的csv文件,如下所示:

let say we want only from column 2 to column 3 and from row 2 to 3, then the result is a new csv file like this:

2,22
3,33

推荐答案

我想主要的问题是hiw可以从给定列/原始数据中捕获数据/变量:1.需要定义范围"及其

I guess the main question is hiw to catch the data/variable from tbe given column/ raw: 1. need to define the "range" and it

2使用"value2()"获取数据

2 take the data with "value2()"

关于外观,它不能同时":您必须确定程序目标.谢谢!

Regarding the look, it just cannot be "at the same time": you have to decide the program goal. thanks!

很抱歉,但此代码插入操作还不够用,所以我放了一张图片:

I am sorry but not quite used with this code inserting, so I put an image:

在此处输入图片描述

这篇关于从第x列到y列以及从第1行到第2行提取csv数据c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆