Reputation: 5522
I have a small application that was written for Linux and now was ported to Windows. It's single-threaded and uses boost (If it matters).
The application is trying to write to a text file using the following code:
m_oFile.open(oFileName.c_str());
if(!m_oFile.is_open())
{
cerr << "Unable to open output file: " << oFileName.c_str() << endl;
exit(0);
}
m_oFile << "some text goes here\n";
m_oFile is a member of the class.
The file is created and opened successfully; the exception is thrown at the last code line above.
Stack trace:
msvcr100.dll!_lock_file(_iobuf * pf) Line 236 + 0xa bytes C
App.exe!std::basic_filebuf<char,std::char_traits<char> >::_Lock() Line 310 + 0xf bytes C++
App.exe!std::basic_ostream<char,std::char_traits<char> >::_Sentry_base::_Sentry_base(std::basic_ostream<char,std::char_traits<char> > & _Ostr) Line 93 + 0x30 bytes C++
App.exe!std::basic_ostream<char,std::char_traits<char> >::sentry::sentry(std::basic_ostream<char,std::char_traits<char> > & _Ostr) Line 114 + x3a bytes C++
Thanks!
EDIT:
When I changed the Code Generation properties to use Multi Threaded Debug Dll (/MDd) instead of Multi Threaded Dll (/MD) everything runs properly. Do you have any explanation for that?
Thanks again.
Upvotes: 2
Views: 1660
Reputation:
Oh - the msvc incompatibility of libraries nightmare - yep make sure all(!) libraries match each other.
Upvotes: 1
Reputation: 21528
Take a look here and try to open your file in read/write mode.
m_oFile.open(oFileName.c_str(), ios::out | ios::in);
Otherwise, check file's permissions.
Remember to always close your file at the end.
m_oFile.close();
Another hit: could the file be used from another thread?
Upvotes: 0