covert between char* to cstring.

I have two problem in my app.

1
2
3
4
5
6
7
8
9
fstream file;
	file.open(filePath.GetString());
	file.seekp(0, ios::end);
	int length = file.tellp();
	file.seekp(0,ios::beg);
	char* buffer=new char[length];
	file.read(buffer ,length);
	CString DataStr(buffer);
	TRACE(DataDtr);


1- when reading file I have some extra that char I didn't know where they come from?(I think I have mistake in read file's size)

2- after reading data I want to change it to CString but when I TRACE(SCtring) it send me "_CrtDbgReport: String too long or IO Error"?

Help
Tnx
When you want to read strings, you should use >> operator, std::getline or a similar function. fstream::read is designed for binary files. It does not append a null char in the end to make a cstring.

If you, for some reason, wish to use fstream::read, you can append 0 manually: buffer[length-1] = 0;
Topic archived. No new replies allowed.