VS2017 c++ ifstream error

0

I've just installed Visual Studio to start writing C++ there, I spent the last year learning in CodeBlocks and everything was going fine. But when I got to trying out the ifstream function, it shoots out an error and I've looked around and can't seem to find an answer anywhere. Could you guys please help?

Here's the very simple code that I wrote:

#include "stdafx.h"
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n, m[100];
    ifstream f1("in.txt");
    f1 >> n;
    for (int i; i < n; i++)
    {
        f1 >> m[i];
        cout << m[i] << endl;
    }
    f1.close();
    system("pause");
    return 0;
}

This is the in.txt path C:\Users\Administratar\source\repos\ConsApp1\in.txt

And this is what is inside in.txt

4
1
2
3
4

And the error says: "Error: Unable to open file C:\Users\Administratar\source\repos\ConsApp1\Debug\ConsApp1.obj Error code = 0x80070002"

c++
asked on Stack Overflow Apr 23, 2018 by Ron K

1 Answer

0

I had a similar issue just now, actually, but the problem wasn't in ifstream or the include at all. It was in the file included previous of it. Just check stdafx.h file and make sure there's no issues or errors in it and it shall work perfectly fine.

answered on Stack Overflow Apr 21, 2019 by Rou

User contributions licensed under CC BY-SA 3.0