我有一些文件编写代码按预期工作,但在调试模式下输出错误,在Release中没有输出错误.
码:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main (int argc, char * const argv[]) {
string cppfilename;
std::cout << "Please enter the filename to create: ";
while ( cppfilename == "" ) {
getline(cin, cppfilename); // error occurs here
}
cppfilename += ".txt";
ofstream fileout;
fileout.open( cppfilename.c_str() );
fileout << "Writing this to a file.\n";
fileout.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调试输出:
Please enter the filename to create: Running…
myfile
FileIO(5403) malloc: *** error for …Run Code Online (Sandbox Code Playgroud)