Basic read file program using Xcode

So basically, I was trying to read a file using C++ and Xcode, and since I haven't coded in a while, I was having some issues. I started to suspect that something was wrong, because the program wasn't reading anything from the file. So I broke it down to the following code, just to try and understand the basics of what was going wrong. I used the file 'trythis.txt', which consisted solely of the letter 'a'. I stored it in the same folder as main.cpp, so it's right there for the program to find it.

Anyways, I'm getting no output, and depending on whether I tweak something or not, I sometimes get an upside down question mark. Any ideas on what's going on here? Or did I just make a basic error in the program?

Thanks,
Luke

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>


using namespace std;



int main()
{
    ifstream infile;
    infile.open("trythis.txt");
    char output[100];        
    infile >> output;
    cout << output << endl;
    
    
    infile.close();
    return 0;
    
}
your program works fine!!
Topic archived. No new replies allowed.