阅读文字和写一个csv文件 [英] Reading text & writing a csv file

查看:92
本文介绍了阅读文字和写一个csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在研究c ++中的一个要求,我将阅读文本文件,其中包含输入,例如

currently I am working on a requirement in c++ where I will be reading text file which have inputs like

AB,
ABX,
ABY,
ABZ,
CD,
CDX,
CDY,
CDZ



所以以上两套输入'AB'和& 'CD'在每一组中都是独一无二的。



我在数组中收集的所有这些输入,并进一步传递给一个用API编写的未暴露的函数,因此API函数返回的输出主要是输入,需要在csv中写入,例如



1.Input-'AB','AB'的o / p,o /''ABX',o / p'ABY',o / p'ABZ'

2.Input -'CD',o / p of'CD',o / p of 'CDX',o / p'CDY',o / p'CDZ'



和我没有得到输出的输入他们应该写成空白。



我尝试了什么:



我能够在运行循环和帮助的帮助下实现把它写在csv中,但我面临着API函数没有返回值的输入的挑战。现在我想收集Vector中的所有输入。我将通过将其传递给API函数在Map中收集的输出将比较输入和输出数据结构以生成输出csv文件。我是否朝着正确的方向实现这一目标,或者我应该尝试其他任何方法?


so for above two set of inputs 'AB' & 'CD' is unique in each set.

all these inputs I am collecting in an array and further passing to a function which is written in API which is not exposed , So API Function is returning output for mostly input which need to write in a csv like

1.Input-'AB',o/p of 'AB',o/p of 'ABX',o/p of 'ABY',o/p of 'ABZ'
2.Input-'CD',o/p of 'CD',o/p of 'CDX',o/p of 'CDY',o/p of 'CDZ'

and inputs for which I am not getting outputs they should be written as blank.

What I have tried:

This I am able to achieve with the help of running loops & write it in csv but I am facing the challenge for the inputs for which API function is not returning value . Now I am thinking to collect all the inputs in a Vector. The output I will collect in a Map by passing it to the API function will compare the input and output data structure to generate the output csv file. Am I in the right direction to achieve this or I should try any other approach?

推荐答案

您需要在两个地方修复代码。

1.修复API,使其在输入没有输出时返回可识别的值。显而易见的值为NULL。

2.修复主代码,使其识别无输出值并写入空白行或其他任何您想要的内容。
You need to fix the code in two places.
1. Fix the API so it returns a recognizable value when an input has no outputs. The obvious value being NULL.
2. Fix your main code so it recognizes the 'no output' value and writes the blank line, or whatever else you desire.


这篇关于阅读文字和写一个csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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