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:
Reading into an integer will stop at the decimal point. You will need to add additional code to either ignore any additional text up to the next space, read into a type like a double, or something similar.