Getting program to open text file
May 8, 2013 at 3:57am UTC
The program is supposed read checker board moves from a text file and print them to the screen. Everything compiles correctly but it keeps saying ""Error opening file, the program will close" meaning the file is not being opened. What am I doing wrong?
Data File:
UL 2
DL 5
UR 6
DL 7
DR 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <fstream>
#include <string>
#include <iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
int numOfSpaces, counter = 0;
string direction;
ifstream intData;
intData.open("C:\\Users\T_Dub\Desktop\data.txt" );
if (!intData)
{
cout<<"Error opening file, the program will close.\n\n" ;
getch();
return 0;
}
while ( !( intData.eof() ) )
{
intData >> direction >> numOfSpaces;
cout << direction << numOfSpaces <<endl;
}
getch();
intData.close();
return 0;
}
Last edited on May 8, 2013 at 4:02am UTC
May 8, 2013 at 4:40am UTC
intData.open("C:\\Users\\T_Dub\\Desktop\\data.txt" );
or, better:
intData.open("C:/Users/T_Dub/Desktop/data.txt" );
Topic archived. No new replies allowed.