File path problem

I tried using this program to see if the file path was corret, but apparently it's not. I don't know what the problem is. The text file is located in the root of the C drive.

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
int sum = 0;
int x;
ifstream inFile;
ofstream outFile;

inFile.open("C:\\text1");
outFile.open("C:\\text2");

if (!inFile)
{
cout << "Unable to open file";
exit(1); // terminate with error
}

while (inFile >> x)
{
sum = sum + x;
}

cout << "Sum = " << sum << endl;
outFile << "Sum = " << sum << endl;
inFile.close();
outFile.close();

return 0;
}
try putting .txt on the end of the filenames, I'm not sure if it's necessary but it's all I can think of
If the name of the file is actually text1.txt, it's totally necessary. :)
Topic archived. No new replies allowed.