i have this file (a:\inputs\data5.txt) in A drive, i want my text.cpp to open it, how ?
How to write a C++ statement to open this file, a:\inputs\data5.txt?
I better use Standard FIle I/O instead of iostream. I like to do so. it's easy to manipulate as char[].
try this...
#include %26lt;stdio.h%26gt;
void main()
{
FILE *fp;
fp=fopen("data5.txt","r");
if (!fp)
{
// do something when error found
}
else
{
char buff[256];
while(!feof(fp))
{
fgets(buff,256,fp);
printf("%s",buff);
}
fclose(fp);
}
}
Reply:the first answer was right, but you may have to specify the full path name of data5.txt, for some reason my programs can never open files if i dont specifiy full path name even if it is in the same folder, and dont forget to make double backslashes becuz its an escape sequence
business cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment