English 中文(简体)
将列分隔成数列,同时区分行中的内容
原标题:Parsing columns into arrays, while discriminating whats in the rows
  • 时间:2012-05-23 14:39:19
  •  标签:
  • c++

我试图解析一个像下面的例子一样输出的文本文件, 我的例子有有限的条目, 但我的实际文件有超过15000行, 所以我无法单独读取这些 :

ID IC 时

15:23:43.867/g/mydata/dataoutputfile.txt 识别符号

0003 1233 abcd

00 43 eb54 abf3

000f 0bb4 ac24

000 a325 ac75

0023 0043 ac91 15:23:44.000 /g/mydata/dataoutputfile.txt identifier

0003 1233 abcd

00 43 eb54 abf3

000f 0bb4 ac24

000 a325 ac75

0023 0043 ac91

是一种我拥有的输出。 时间列经常重置 。

我现在正在做的是,除了我的例子中的3个栏外,再增加2个栏。第一栏是将ID栏转换为可理解的信息。第二栏将计算每个时间代码之间的差异,但时间代码重置除外。

我的逻辑是,把每一列都读成一个阵列 这样我就能完成必要的翻译和操作

我的重点是先拿到时间代码差数, 因为我认为得到翻译会比较简单。

我的问题是把条目读入他们的矩阵表:

我的代码看起来有点像这个

while(readOK && getline(myfile,line))
{
stringstream ss(line);
string ident,IC,timehex,time,filelocation;
string junk1,junk2;
int ID[count];
int timecode[count2];
int idx=0;

if(line.find("ID") !=string::npos)
{
     readOK=ss>>ident>>IC>>timehex;
     myfile2<<ident<<"		"<<IC<<"		"<<timehex<<"		"<<"ID Decoded"<<"		"<<"DT"<<endl;
     myfile3<<"headers read"<<endl
}

else if(line.find("identifier") != string::npos)
{
     readOK=ss>>time>>filelocation;
     myfile3<<"time and location read";
     myfile2<<time<<"		"<<filelocation<<endl;
}

else //this is for the hex code lines
{
     readOK=ss>>hex>>ID[idx]>>IC>>timecode[idx];

     if (readOK)
     {
          myfile2<<setw(4)<<setfill( 0 )<<hex<<ID[1000]<<"		"<<IC<<"		"<<timecode[1000]<<endl;
          myfile3<<"success reading info into arrays"<<endl;
     }

     else
     myfile3<<"error reading hex codes"<<endl;
}
idx++;
}

虽然这个代码工作不正确, 我无法在每行都读一样的字, 因为插入了中间的时间和文件位置条目, 帮助记录我读到代码时的状态 。

我的直觉告诉我,我打给矩阵条目的时间太早了,它们还没有被填满,因为如果我用1000计数,我就会得到一个0(我的输入文件中有超过15000行,我在我的程序的另一部分动态地设置了阵列的界限)。

我似乎无法找出如何正确分配条目, 因为我有些继承问题, 数数变量每次在循环中调整为0。

问题回答

定义 int idx 在循环范围之外( 之前) 。 现在的情况是, 每次通过循环, 它都会被重置 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签