Hi everyone,
I have text file like this:
516457 +9989704016796.0 1
516471 +9989844018787.0 1
516481 +9989984013367.0 1
516484 +9990124023453.0 1
76516 +9990264014313.0 2
76522 +9990404025578.0 2
76541 +9990544016397.0 2
76561 +9990684018087.0 2
77081 +9990824015982.0 2
I want to read each column separately, below is my code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdint.h>
#include <sstream>
#include <typeinfo>
using namespace std;
int main()
{
int pos,pos2,pos3;
ifstream inf;
inf.open ("123.txt");
if (inf.is_open())
{
while (getline(inf,line))
{
if (line.find("Pkt_recv") != string::npos)
{
pos=line.find(word1);
pos3=line.find(word3);
line.replace(pos,word1.length(),"");
line.replace(pos3,word3.length(),"");
//inf >> a >> b >> c;
//cout << a << b << c << endl;
}
inf.close();
}
else cout << "Unable to open file inf \n";
return 0;
}
I could to get the values of column 1 and 2 and save in variables column1 and column2 but I could not get the third column value of text file. I do not know what is the problem. anyone can help me please. below is the output of mentioned code:
Line 22: What does "Pkt_recv" have to do with any of the sample input you've shown?
Line 24-25: word1, word3 undefined.
column 2 is in double format. Suggest reading it into a double. Otherwise, you're going to be left with a '.' as the next character in the input buffer.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thanks for your reply
Yep, I changed the type into double_t and it is working now.
I am new member here and this is the first topic. I will use code tags in future.