All I need to do is a simple read from a file in the same directory, but for some reason it refuses to work.
It works perfectly fine in this quick test one I made after I had problems, and outputs the number of entries in the text file.
#include <iostream>
using std::cout;
using std::cin;
#include <cstdio>
int main()
{
int a;
int b = 0;
freopen ("7.txt", "r", stdin);
while (cin >> a)
++b;
cin.clear();
fclose (stdin);
freopen ("7.txt", "r", stdin);
cout << b << '\n';
fclose (stdin);
}
EDIT: Wow I’m sorry to everyone who tried wrapping their heads around this. It was pretty late when I posted this, but I thought I finished. Apparently not. Now upon reopening my file to post the code in it, I realize that I moved everything into a folder before, but apparently when I tried to run the actual thing, it saved back outside of the folder, so it couldn’t open “7.txt”.
Problem solved I guess, sad waste of space seeing as how it wasn’t even complete O_o, sorry.
EDIT2: Okay now I’m confused. I had a temp account on this computer, but when I logged into this account to ask a different question, this one as I meant to post it the other night showed up. I wasn’t even on this computer while asking it. Not sure why it wasn’t posted like that if it was all ready to be though.
My best “guess” is that you are trying to re-read the same file. If this is the case then you could try this :
Please try and formulate better questions in the future.