Xcode STL C ++ Debug编译错误 [英] Xcode STL C++ Debug compile error
本文介绍了Xcode STL C ++ Debug编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
我有一些文件编写代码工作正常,但打印错误在调试模式,没有输出错误。 strong> #include< iostream>
#include< string>
#include< fstream>
#include< sstream>
using namespace std;
int main(int argc,char * const argv []){
string cppfilename;
std :: cout<< 请输入要创建的文件名:;
while(cppfilename ==){
getline(cin,cppfilename); //错误出现在这里
}
cppfilename + =.txt;
ofstream fileout;
fileout.open(cppfilename.c_str());
fileout< 将此文件写入file.\\\
;
fileout.close();
return 0;
}
调试输出:
请输入要创建的文件名:运行...
myfile
FileIO(5403)malloc:***错误对象0xb3e8:指针被释放
***在malloc_error_break中设置断点以调试
创建:myfile.txt
发布输出:
FileIO实现C ++
输入要创建的文件名:Running ...
myfile
创建:myfile.txt
除了不检查文件描述符是否打开(为了简单)这个代码有什么问题?
更新:下面的代码仍然存在错误:
string cppfilename;
getline(cin,cppfilename); //错误在这里
解决方案
这看起来是另一种情况 _GLIBCXX_DEBUG在Mac OS X上使用gcc 4.2中断。
您最好的选择是删除_GLIBCXX_DEBUG或切换到gcc 4.0。
I have some file writing code that works as expected, but prints an error on Debug mode, no output errors in Release.
Code:
#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;
}
Debug Output:
Please enter the filename to create: Running…
myfile
FileIO(5403) malloc: *** error for object 0xb3e8: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Created: myfile.txt
Release Output:
FileIO implementation C++
Please enter the filename to create: Running…
myfile
Created: myfile.txt
Aside from not checking for the file descriptor being open (for simplicity) what is wrong with this code?
Update: I broke the code down to the following and it still errors:
string cppfilename;
getline(cin, cppfilename); // error here
解决方案
This looks to be another case of _GLIBCXX_DEBUG being broken with gcc 4.2 on Mac OS X.
Your best options look to be to drop _GLIBCXX_DEBUG or to switch to gcc 4.0.
这篇关于Xcode STL C ++ Debug编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文