Xcode STL C ++ Debug编译错误

编程入门 行业动态 更新时间:2024-10-27 01:24:39
本文介绍了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编译错误

本文发布于:2023-11-13 11:57:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584296.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Xcode   STL   Debug

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!