String Stream Fail To Capture Double Numeric

Dear all,

I have data that contain lines like this:
 
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  223636  256838.120


They are tab separated.



With this code of mine, using string stream
we would like to capture the 2nd and 3rd field as double.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;


int main  ( int arg_count, char *arg_vec[] ) {
    if (arg_count !=2 ) {
        cerr << "expected one argument" << endl;
        return EXIT_FAILURE;
    }

    string line;
    ifstream myfile (arg_vec[1]);


    if (myfile.is_open())
    {
        while (getline(myfile,line) )
        {
            stringstream ss(line);  
            string TAG;
            double OBS;
            double EST; 
        
            ss >> TAG >> OBS >> EST; 
            cout << TAG << "\t" << OBS << "\t" << EST << endl;

    
        }
        myfile.close();
    }
    
    else cout << "Unable to open file";
    return 0; 
}  


However it prints only the integer like this:
 
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  223636  256838


What's wrong with my code above?
Last edited on
Try using the setprecision manipulator on line 28
Topic archived. No new replies allowed.