-
stdin or a file
In C i was able to do things like...
Code:
FILE* file_in;
file_in = stdin;
And then if i want to actually read from a file i just change what file_in is pointing at. When i try to do this in C++ i just get a bunch of errors that i cant read. Is there a way to do this in C++?
-
Maybe I'm missing something, but this works in C++.
PHP Code:
FILE* file_in;
char test[256];
file_in = stdin;
fgets(test,256,file_in);
printf("%s",test);
file_in = fopen("file.txt","r");
fgets(test,256,file_in);
printf("%s",test);
fclose(file_in);
-
You are missing something. Thats C code. I want to use C++. C++ is based on C. Every C program will compile in C++.