Need some help with I/O File program

I am trying to run this simple program below:

#include<iostream>
#include<fstream>

using namespace std;

int main(void)
{
ifstream openFile("d:\fkjkj.txt");
char ch;
while(!openFile.eof())
{
openFile.get(ch);
cout<<ch;
}
openFile.close();

return 0;
}


This compiles and run but gives weird output. It shows some weird characters infinitely when it runs. Can anyone help?
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
#include<iostream>
#include<fstream>

using namespace std;

int main(void)
{
// You must use double slash in paths (\\) or a single forward slash( /)
ifstream openFile("d:\\fkjkj.txt"); // or   "d:/fkjkj.txt"

// You should check whether file is open
if(!openFile.is_open())
  {
     cout <<"could not open file";
     return 1; 
  }

char ch;
while(!openFile.eof())
{
openFile.get(ch);
cout<<ch;
}
openFile.close();

return 0;
}
Last edited on
Thanks, I will try that.
Topic archived. No new replies allowed.