How can i read and write text to and from a text file? I was experimenting with this code, but it places some random text into the text variable and i get a bunch of access violations.

Here's the code:

ccode

#include <iostream>
#define _AFXDLL
#include <afx.h>
using namespace std;

int main()

{

char text[4];
const int max=10;
char letter[max];


CStdioFile file;
bool bSuccess = file.Open(("c:\_averyunlikelyname.txt"),
CFile::modeRead |
CFile::typeText
);
if (!bSuccess)
return FALSE;
file.ReadString(text,3);

cout << "The text from the file is: " << text;
cin >> "press enter to continue";

return 0;

}
/ccode


any help would be appreciated. thanks.