从文件中提取值并执行计算 [英] Extract Values from a file and perform calculations

查看:60
本文介绍了从文件中提取值并执行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

>我正在从事一个涉及从.npd格式的文件中提取值的项目(这不是我的问题),然后执行一些计算.
该文件包含几列数据(没有任何标题).我必须给每一列起一个名字,并做一些计算.

原始文件如下所示:

Hi guys,

>I''m working on a project that involves extracting the values from a file,that is in .npd format(this is not my problem) and then perform some calculations.
The file contains several columns of data(without any heading). I have to give each column a name, and do some calculations.

The raw file looks like :

1 $Abc 21:00:55 20 33 56 1 $Abc 21:00:56 22 34 56 
2 $Abc 22:00:34 43 30 45 2 $Abc 22:00:35 44 36 45
3 $Abc 22:23:23 19 88 67 3 $Abc 22:23:24 12 82 63
4 $Abc 23:40:29 20 20 20 4 $Abc 23:40:30 26 26 24
5 $Abc 23:55:00 34 21 28 5 $Abc 23:55:01 37 26 29  



1)我必须在第二,第三和第四列上执行计算,并将其打印在标题为的文件上(我刚刚设法完成了此操作).例如,将每个值加1并指定标题.
2)我必须删除从第6列开始的值!我不能使用tokenise方法,使用"$"作为定界符,因为有2列以符号"$"开头.我希望值开始
last6列必须完全删除.



1)I have to perform calculations on the 2nd, 3rd and 4th column and print it on a file with heading( Which I managed to do just now). for example add 1 to each value and give headings.
2)I have to delete the values starting from the 6th column!! I cannot use tokenise method, using "$" as delimiters because there are 2 columns starting with the symbol "$". And I want the values starting
The last6 columns must be completely removed.

Heading1 Heading 2 Heading 3
21       34        57         
44       31        46
20       89        67 
21       21        21
35       22        29



2)然后找到每列的平均值.



2) Then find the mean of each column.

Mean of column 1:
Mean of column 2: 
Mean of column 3: 



此外,其中一列还包含"N",要计算的列在该列的左侧.
我知道如何打开文件,但是对数据进行排序有点混乱,请帮忙,示例将非常有帮助! [更新]

我使用此代码从第4列获取值,但是无法对这些值进行任何计算.例如:



Also one of the columns contain ''N'' and the column to be calculated is to the left of this column.
I know how to open the file, but sorting the data is a bit confusing, please help, Examples would be very helpful!!!
[Update]

I used this code to get the value from the 4th column, but I cannot make any calculations on these values. for example :

void main{
str(_T("%21:00:55 $GPGGA 210055 6102.00399 six"));
CAtlString resToken;
int curPos = 24;
double val;
resToken= str.Tokenize(_T(" "),curPos);
_tprintf_s(_T("Resulting token: %s\n"), resToken);
}


这将打印第4列的值,但是我必须对该变量进行一些计算,为此,我必须将字符串从double转换为double并转换回string以打印值.这可行吗?

[/Update]


This prints the 4th column value but I have to do some calculation on that variable, For which I have to convert from string to double and back to string to print the values. Is this feasible?

[/Update]

推荐答案

Abc 21:00:55 20 33 56 1
Abc 21:00:55 20 33 56 1


Abc 21:00:56 22 34 56 2
Abc 21:00:56 22 34 56 2


Abc 22:00:34 43 30 45 2
Abc 22:00:34 43 30 45 2


这篇关于从文件中提取值并执行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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