Results 1 to 3 of 3

Thread: stdin or a file

  1. #1
    ChimpFace9000
    Guest

    Post 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++?

  2. #2
    Member
    Join Date
    Feb 2001
    Posts
    57
    Maybe I'm missing something, but this works in C++.

    PHP Code:
    FILEfile_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); 

  3. #3
    ChimpFace9000
    Guest
    You are missing something. Thats C code. I want to use C++. C++ is based on C. Every C program will compile in C++.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width