Hi,
I am having problems with a function that I have been using in my program to
read sentences from a 'command file' and parse them into commands. the
surprising thing is that the program works fine on some computers and not so
fine on others. I tried debugging and cannot make any sense of it. I
narrowed it down to the seekg function and made this simple program which
(from what I understand) does not seem to be working as expected in all the
computers I have tried so far.
please let me know if I have got something wrong...
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream is("test.txt") ;
char test[256];
is >test;
cout << test << endl;
is.seekg(-2,ios::cur);
is >test;
cout << test << endl;
return 0;
}
here are the different versions of test.txt and their corresponding outputs
in all the cases I expected that the output would be
createModel
el
what am I doing wrong ?
case 1: contents of test.txt :
createModel
OUTPUT:
createModel
del
case 2: contents of test.txt
createModel
testing
/*
*/
OUTPUT:
createModel
eModel
case 3: contents of test.txt :
createModel
testing
/*
*/
CreateElements
196
DMElasticElemen t
0 195 1
-1
exitCreateEleme nts
OUTPUT:
createModel
thanks
Julian.
I am having problems with a function that I have been using in my program to
read sentences from a 'command file' and parse them into commands. the
surprising thing is that the program works fine on some computers and not so
fine on others. I tried debugging and cannot make any sense of it. I
narrowed it down to the seekg function and made this simple program which
(from what I understand) does not seem to be working as expected in all the
computers I have tried so far.
please let me know if I have got something wrong...
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream is("test.txt") ;
char test[256];
is >test;
cout << test << endl;
is.seekg(-2,ios::cur);
is >test;
cout << test << endl;
return 0;
}
here are the different versions of test.txt and their corresponding outputs
in all the cases I expected that the output would be
createModel
el
what am I doing wrong ?
case 1: contents of test.txt :
createModel
OUTPUT:
createModel
del
case 2: contents of test.txt
createModel
testing
/*
*/
OUTPUT:
createModel
eModel
case 3: contents of test.txt :
createModel
testing
/*
*/
CreateElements
196
DMElasticElemen t
0 195 1
-1
exitCreateEleme nts
OUTPUT:
createModel
thanks
Julian.
Comment