English 中文(简体)
比较档案中的线体
原标题:Comparing lines of strings from a file
  • 时间:2011-11-21 06:45:46
  •  标签:
  • c++

我读过一个文件,我想读到每个字段,看上去的是,如果每个字段是直线和比较,以找到某些关键词,如果我发现这些关键词,在这些关键词中做一切,并作新的解释。 有可能有一条以上与同样关键词的界线,因此,我想另立一条示...。

现在我看着一些看得见的法典,那就是,有人会bar地在这里,让我看到如何这样做的正确方向。

I can put my code here if you like, but I ll have to explain it a lot.

AGU UACAUU GCG CGA UGG 海湾合作委员会

GUU ACA UUG CGC GAU GGG CCU CGA GAC CCG GGU UUA AAG UAG GUG A

UUA CAU UGCG M GGC CUC GAGAC CGG GUUA AGU AGG UGA

UGG M AAUUU GG CCC AGA GCU CCG GGU AGCG UUA CAU

这将成为我的文本的一部分。 我想找到M,然后发现:1)UA,2)UAG,3)UGA。 这样,我可以比较一下他们的时间。 我尝试使用指派操作员,但每次都会印刷同样的插图。

ED。 我猜测,我所想的是,在我这样做的时候,我只是想把这整个一线变成一个扼子,以便我能够比较一下。

ifstream code_File ("example.txt");   // open text file.
if (code_File.is_open()) {
    while (code_File.good()) {


        getline(code_File,line);    //get the contents of file 
        cout  << line << endl;     // output contents of file on screen.


            found = line.find_first_of( M , 0);               // Finding start code
        if (found != string::npos) {
           code_Assign.assign(line, int(found), 100);        //assign the line to code_Assign and print out string from where I found the start code  M .

            cout << endl << "code_Assign: " << code_Assign << endl << endl;
问题回答

这似乎是<代码>grep或sedaw标准Pos.6公用事业的良好任务。

如果你想要在方案内使用标准,parsing techiques e.g with ANTLR

然而,我不明白你试图做些什么:

读到一条线,将其放在一个单一体内:使用<代码>std:getline。

To find a fixed string in another string, use std::search; for more complicated patterns, use boost::regex (or std::regex if you have a C++11 compiler). std::search will return an iterator, and two iterators can be used to construct a new string. The regex solutions can “capture”, so you have access to the intervening string directly (or not; a lot depends on how complicated the pattern is, and the regex solution doesn t work when the string you want to capture is in a repeated pattern). Without more information, however, it is difficult to say more.

Try specifying your problem precisely; I think you ll find that that helps in finding a solution.





相关问题
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?

热门标签