no string just hex?

I've included string: '#include<string>' but when I try to make my variable a string it doesn't want to work. Also, when i execute the program, it comes out in hex. And the weird thing is, is it doesn't matter what text file I give it. It keeps printing out '0x22fed4'... which also was strange to me. Any help would be appreciated. Mostly I need help on the string part though. It didn't even give me an error! Odd...

Here you go:

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
#include <iostream>
#include <fstream>
#include <string>  
//something wrong here?
#include "io0.h"
using namespace std;

string myDataFile; //or here? I'm lost... 
                   
int main()
{
	
ifstream myDataFile;

myDataFile.open("rileyfile.txt");

if (myDataFile.good())
{
	cout << "\nFile opened!! Reading..." << endl;
	cout << myDataFile << endl;	
}
	
system("PAUSE");
return 0;
}



Thanks a lot in advance!

-Scooter

I believe it is because myDataFile is an ifstream...I think you meant ofstream (output file stream).
No... I do want the file inputted into the main function. I need to read the file in and then do some other stuff with it. I did try it though, and it just returned '0x22fed0'.....
ofstream means you get data from the user (or somewhere) and put it into the file.

ifstream means you get data from the file and cout it on the screen (or do something with it)

fstream does both.

Which one did you want?
Last edited on
What?!
istreams (like any other kind of input) are for input into memory. An ifstream is therefore for reading files, and viceversa.
The problem here is that you're not reading the file, you're just printing the pointer to the stream. And pointers are always printed in hex.
Last edited on
Blargh!! I *ALWAYS* mess that up...XP
But I can't see why it outputs the pointer instead of the data... any help?
Remember that a stream is not a string. You have to either read the file character by character or into a buffer. Reading into a buffer is always faster.
see the istream reference for more info.
http://www.cplusplus.com/reference/iostream/ifstream/
Topic archived. No new replies allowed.