View Full Version: char text[]

C++ Learning Community > win32 api C++ programming > char text[]


Title: char text[]


Dragon - July 4, 2003 03:09 AM (GMT)
I know that this works: char text[] = "Hello";. How would I set text to a value read from a file? I tried doing this, but it didn't work:

#include <fstream>

using namespace std;

int main()
{
ifstream in("atextfile.txt");
char text[];
}

Some help, please?

Xception - July 4, 2003 11:44 AM (GMT)
I don't know what ifstream in() does?
You could do it this way:
CODE

#include <iostream.h>
#include <conio.h>
#include <fstream.h>

ifstream *f;

int main() {
char text[10];
f=new ifstream("test.txt",ios::in,0);
f->read(text,5);
delete f;
text[5]=0;
cout<< text;
getch();
return 0;
}

Dragon - July 4, 2003 07:45 PM (GMT)
Thanks, Xception. I'll see if that works.




* Hosted for free by InvisionFree