Hey all,
writing up some code to copy a string from a text file and extract numbers from the string. What I have so far is:

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[]){
   ifstream in("test.txt");
   if(!in){
      cout << "Cannot open file.";
      exit (1);
   }
   char str[255];
   while(in){
      in.getline(str, 255);
const string data = str;

int HEAD, DAY, MONTH, YEAR, HOUR;

HEAD	= atoi( data.substr(0,4).c_str() );
DAY = atoi( data.substr(4,2).c_str() );
MONTH = atoi( data.substr(6,2).c_str() );
YEAR = atoi( data.substr(8,2).c_str() );
HOUR = atoi( data.substr(10,2).c_str() );

I am getting no errors but the program is not running. Does anyone have any ideas. Thanks in advance.
Colm

what do you mean by "it is not running" ?

Why don't you get rid of that charcater array and read the line directly into the string.

string data;
while( getline(in, data) )
{

   // blabla
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.