How to Read from a Text File, Character by Character in C++

后端 未结 8 1814
孤街浪徒
孤街浪徒 2020-12-06 10:17

I was wondering if someone could help me figure out how to read from a text file in C++, character by character. That way, I could have a while loop (while there\'s still te

8条回答
  •  情话喂你
    2020-12-06 10:44

    There is no reason not to use C in C++, and in fact it is often the optimal choice.

    #include 
    
    int
    main()  // (void) not necessary in C++
    {
        int c;
        while ((c = getchar()) != EOF) {
            // do something with 'c' here
        }
        return 0; // technically not necessary in C++ but still good style
    }
    

提交回复
热议问题