Getline-Fehler MFC vs2012 (msvcp110.dll)
Ich habe ein Problem, die std :: getline-Funktion in vs2012 mit einer MFC-Anwendung zu verwenden. Derselbe Code wurde in vs2010 ausgeführt, daher bin ich sicher, dass es kein Problem mit dem Code selbst gibt.
void AddImage::OnClickedIdbAiRegistration(){
CFileDialog file(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, "(*.dat)|*.dat||");
file.DoModal();
UpdateData();
m_ai_file=file.GetPathName();
UpdateData(FALSE);
std::string buf=m_ai_file;
if(filecnt(buf, "Dat")){
std::ifstream file(buf);
AfxMessageBox(buf.c_str());
std::getline(file, buf);//Here is my problem
AfxMessageBox(buf.c_str());
file.close();
}
}
Die erste AfxMessageBox gibt den Dateipfad zurück (der korrekt ist und eine gültige ASCII-Datei enthält). Die zweite AfxMessageBox erreiche ich nie, weil getline erzeugt:
Nicht behandelte Ausnahme bei 0x000007FEF7B4AAEE (msvcp110.dll) in program.exe: 0xC0000005: Zugriffsverletzung beim Lesen des Speicherorts 0xFFFFFFFFFFFFFF.
und vs11 leiten mich zur xiosbase-Leitung 443 weiter
locale __CLR_OR_THIS_CALL getloc() const
{ // get locale
return (*_Ploc);/*THIS IS LINE 443*/
}
Für die Projekteigenschaft verwende ich "Use MFC in a shared DLL" und "Multi-Threaded DLL" und Sub-System "Windows"
Zusätzlicher Programmcode und beinhaltet:
#include <afxwin.h>
#include <afxframewndex.h>
#include <afxcmn.h>
#include <afxdialogex.h>
#include <iostream>
#include <string>
#include <sstream>
#include <regex>
#include <fstream>
#include <time.h>
#include <Windows.h>
usign namespace std;
class AddImage:public CDialog{
DECLARE_DYNAMIC(AddImage)
public:
AddImage(CWnd* pParent = NULL);
virtual ~AddImage();
enum {IDD=IDD_ADD_IMAGE};
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
public:
CString m_ai_file;
};
AddImage::AddImage(CWnd* pParent):CDialog(AddImage::IDD, pParent){
m_ai_file=_T("");
}
AddImage::~AddImage(){
}
bool filecnt(string path, string type){
if(filepathcnt(path, type)){
if(GetFileAttributes(path.c_str())==-1){
return(FALSE);
}
else{
return(TRUE);
}
}
else{
return(FALSE);
}
}
bool filepathcnt(string path, string type){
if(type==""){
tr1::regex regex("[[:print:]]+\\.[[:alnum:]]+");
if(regex_match(path.begin(), path.end(), regex)){
return(TRUE);
}
else{
return(FALSE);
}
}
else if(type=="-"){
tr1::regex regex("[[:print:]]+");
if(regex_match(path.begin(), path.end(), regex)){
return(TRUE);
}
else{
return(FALSE);
}
}
else{
string upper=type;
string lower=type;
transform(upper.begin(), upper.end(), upper.begin(), toupper);
transform(lower.begin(), lower.end(), lower.begin(), tolower);
tr1::regex norm_regex("[[:print:]]+\\."+type);
tr1::regex upper_regex("[[:print:]]+\\."+upper);
tr1::regex lower_regex("[[:print:]]+\\."+lower);
if(regex_match(path.begin(), path.end(), upper_regex) || regex_match(path.begin(), path.end(), lower_regex) || regex_match(path.begin(), path.end(), norm_regex)){
return(TRUE);
}
else{
return(FALSE);
}
}
}
Hat jemand eine Idee was falsch läuft?