开发者

C++ read file from .txt and holds the desired value in a new .txt using Xcode

The text files are in this format :

No.     Time        Source                Destination           Protocol Info
      1 0.000000    192.168.1.77          203.253.16.41         DNS      Standard query A ksn1.kaspersky-labs.com

Frame 1: 83 bytes on wire (664 bits), 83 bytes captured (664 bits)
Ethernet II, Src: Giga-Byt_58:d7:ce (00:1f:d0:58:d7:ce), Dst: D-Link_c4:eb:4a (00:1b:11:c4:eb:4a)
Internet Protocol, Src: 192.168.1.77 (192.168.1.77), Dst: 203.253.16.41 (203.253.16.41)
User Datagram Protocol, Src Port: discp-server (2602), Dst Port: domain (53)
Domain Name System (query)

I would like a coding in C++ on how to read only the 192.168.1.77 and 203.253.16.41. And then holds the 2 IP address values and output it in another new .txt files.

I am developing this on Mac OS X 10.5.8 using Xcode...

As for now, I'm able to read the first line in 'iplist.txt' and write it to a new file named 'output.txt'. I need help on how to read the second line online using getline()...

Here's the part that i manage to do...

ifstream inFile("iplist.txt");

        getline(inFile,x);

        ofstream outFile ("output.txt");
            if (outFile.is_open())
      开发者_开发问答      {
                outFile << x;
                outFile.close();
            }


Read a line and discard it. Read the next line and break it into fields, keeping the third and fourth. Read the next 6 lines and discard them to get ready for the next record.


Come on. Who uses C++ for that? It is a one-line awk command:

awk '/^[ \t]/ { printf("%s\t%s\n", $3, $4); }' file.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜