how can I read a text file byte by byte?

Recommended Answers

All 3 Replies

Use the .get() method. Here is an example:

istream fileReader("filename.txt");
char byte;
while( fileReader.get(byte) ){
  cout << byte;
}

Are you sure this method return the byte??

when I tried to use it,I find that it's return the character from the txt file.

a charecture is one byte long. to prove this try this code

#include <iostream>

int main()
{
    char ch;
    std::cout << sizeof(char);
    std::cin.get();
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.