Read from txt

Aug 26, 2012 at 12:41am
What is the easiest way to read the first char from a txt? I figured out an extremely over complicated way that looks like a prime example of inefficient programming but was hoping there was a better way. I had an if statement inside the while(getline(x.txt, y)). Any help or advice would be great thanks!
Aug 26, 2012 at 12:58am
Just open the file and read the first character.
1
2
3
4
    std::ifstream is("stuff.txt");

    char ch;
    is >> ch;
Aug 26, 2012 at 1:52am
You might want to add std::noskipws.

is >> std::noskipws >> ch ;

Without it, you would read the first non-whitespace character.
Topic archived. No new replies allowed.