0
내 코드 :ifstream 개체의 .read() 문제
ifstream Reader ("commands.txt");
if(Reader.fail())
{
error("File \"commands.txt\" could not be found or opened.\n");
}
Reader.seekg(0, Reader.end);
int FSize = Reader.tellg();
if(FSize == 0)
{
cout << "File \"commands.txt\" is empty.\n";
return 0;
}
char * ContentsHold = {};
Reader.read(ContentsHold, FSize);
Reader.close();
string Contents(ContentsHold);
아이디어는 말에, 내용이 commands.txt 모든 것을 보유하고 C++ 문자열이어야한다는 것입니다. "basic_string :: _ S_construct null not valid"오류가 발생합니다. 나는 무엇이 잘못되었는지 알 수 없다. 도움? 여기에 무엇을 가지고
'char *'는 포인터가 아니라 배열을 선언합니다. '{}'로 초기화하면 빈 배열을 만들지 않고'nullptr'을 생성하는 포인터를 값 초기화합니다. 대신에 왜 벡터''또는'string'을 사용하고 그 기본 버퍼를 읽지 않습니까? –