PDA

Click to See Complete Forum and Search --> : Read Line Text


Vlatko
Dec 8th, 2000, 01:11 PM
How do i read a line from a text file in a Win32 app. If i use this in a non dos app i get errors:

char buffer[81];
FILE *in_file,*fopen();
char *fgets();
if((in_file = fopen ( "c:\\bootlog.txt","r"))!= NULL )
{
fgets(buffer,81,in_file);
}


Errors:
: error C2660: 'fopen' : function does not take 2 parameters
: error C2660: 'fgets' : function does not take 3 parameters

Vlatko
Dec 8th, 2000, 01:38 PM
I managed to get this to work

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

string str;
ifstream i("c:\\bootlog.txt");
getline(i,str);

HarryW
Dec 8th, 2000, 08:30 PM
Why declare fopen() and fgets()? They're both in stdio.h, so why declare them with a different parameter list? I think if you leave the function declarations out the first bit of code should work.