-1

I need to read into my program some data from .CSV file and I have no idea how to change this number into float. I can use only standard libraries and this file needs to be binary (ios::binary).

This is how it looks like in .csv file:

Lateral.Range(mm),5.000000

How to make this "5.000000" a float?

#include<iostream>
#include<fstream>
#include<cstring>

using namespace std;

int main()
{
    ifstream obraz;
    obraz.open("File_name.csv", ios::binary);

    if(!obraz)
        cerr<<"nie udalo sie otworzyc pliku "<<endl;

    char lat_ran[18]; // text before the number
    float lateral_range;

    obraz.read(lat_ran, sizeof(lat_ran));
    obraz.read(reinterpret_cast<float*>(&lateral_range), sizeof(float)); // I know this part is wrong.

    obraz.close();
}
dragosht
  • 3,237
  • 2
  • 23
  • 32
Artur
  • 25
  • 5

1 Answers1

0

Use >> operator: obraz >> lateral_range;.