如何处理错误cygwin_exception :: open_stackdumpfile

时间:2017-04-26 12:19:50

标签: c++ c++11

有人可以帮我找到解决问题的方法吗?这些错误似乎经常发生,但每次都有其他问题。

我认为我有关于fstream对象大小的问题? 就像在矩阵中发布的错误一样:cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdump



#include<iostream>
#include<fstream>
#include<string>
#include"ReaderWriter/WriterBuild.h"

using namespace std;

string path = "";
string file = "Testdatei.dat";
string message = "hallo";
bool status;

int main(){

//Testklasse erstellen
	cout << "start" << endl;
	WriterBuild Testwriter(&path, &file);
	status = Testwriter.write(&message);
	cout << status << endl;

	//cout << "End";

	return 0;

}
&#13;
&#13;
&#13;

&#13;
&#13;
#ifndef READERWRITER_WRITERBUILD_H_
#define READERWRITER_WRITERBUILD_H_
#include <string>
#include <fstream>
#include <iostream>

namespace std {

class WriterBuild {
public:
	WriterBuild(string *ppathname, string *pfilename);
	virtual ~WriterBuild();
	bool write(string *pmessage);

private:
	fstream* _pfilestream;
	void checkPath(string *ppath);

};

} /* namespace std */

#endif /* READERWRITER_WRITERBUILD_H_ */
&#13;
&#13;
&#13;

&#13;
&#13;
#include "WriterBuild.h"

namespace std {

WriterBuild::WriterBuild(string *ppathname, string *pfilename) {
	// TODO Auto-generated constructor stub
	const char* pfile = pfilename->c_str();
		fstream filestream;
		filestream.open(pfile, ios::out | ios::app);
		_pfilestream = &filestream;
		if (!_pfilestream->good()){
			cout << "Datei existiert nicht." << endl;
		}
		else{
			cout << "Datei existiert" << endl;
			}
		cout << _pfilestream << endl;
}

WriterBuild::~WriterBuild() {
	// TODO Auto-generated destructor stub
	cout << "destructor-start" << endl;
	cout << _pfilestream << endl;
	_pfilestream->close();
	cout << "destructor-ende" << endl;
}

bool WriterBuild::write(string *pmessage){
	cout << "test pmessage: " << pmessage << endl;

	return true;
}

void WriterBuild::checkPath(string *ppath){


}

} /* namespace std */
&#13;
&#13;
&#13;

输出:

enter codstart
Datei existiert
0xffffc940
test pmessage: 0x100407020
1
destructor-start
0xffffc940
105 [main] CMS_W_Engine 11556 cygwin_exception::open_stackdumpfile: Dumping     stack trace to CMS_W_Engine.exe.stackdumpe here

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

在构造函数中,您已将成员变量LLVMConfig.cmake设置为指向堆栈对象_pfilestream的指针。一旦构造函数退出filestream指向的内存,就可以自由重用(意味着其他代码可以自由覆盖该内存)。这意味着您的指针_pfilestream不再是有效_pfilestream,因为它指向的内存不再保证为fstream *

如果你想将fstream保留为成员变量_pfilestream,你应该使用fstream * _pfilestream在构造函数中初始化它,然后在析构函数中关闭它并_pfilestream = new fstream(pfile, ios::out | ios::app);