Hi guys,

I have a txt file in which each line contains information in following format:

LAT_1<N 00 00.0000>
LON_1<E 000 00.0000>

I would like to write a C or C++ programm to select only the values of the words I need. I need those values to do further calculations.
In this example I would need 100.0 and 00 00.0000 and 000 00.0000

I'm just beginning to programm in C, so could anybody help me writing this code?



read each line of the file, then search the line for each of the key words you want to use. For example

std::string line;

if( line.find("VELOCITY") != string::npos)
   // blablas
else if( line.find("LAT_1") != string::npos)
  // blabla
// etc. etc.

>>I'm just beginning to programm in C,
This is the c++ forum, not c forum :)

Edited 6 Years Ago by Ancient Dragon: n/a

Thanks for the help.
I've started as from today with the programming, since I need it for a project this semester and for my thesis and I think I'll be picking up C++.
I've succeeded in reading the file.
The code you wrote, is it looking for everything wich differs from char's? How do I store the value?
I've started with C++ for dummies, but stream I/O is chapter 24, so excuse me if my questions are basic.
Do you advise a better book or website?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int VEL_X;
int LAT;
int LON;
int main ()
  string line;
  ifstream text("NK.txt");
  if (text.is_open())
    while (! text.eof() )
      getline (text,line);
      cout << line << endl;

  else cout << "Unable to open file"; 
  std::string linee;
  if( linee.find("VELOCITY") != string::npos)

  else if( linee.find("LAT_1") != string::npos)

            // blabla


  return 0;



Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

This article has been dead for over six months. Start a new discussion instead.