gpt4 book ai didi

c++ - Getline 错误 MFC vs2012 (msvcp110.dll)

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:45 25 4
gpt4 key购买 nike

我在 vs2012 中将 std::getline 函数与 MFC 应用程序一起使用时遇到问题。相同的代码在 vs2010 中运行,这就是为什么我确信这不是代码本身的问题。

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();
}
}

第一个 AfxMessageBox 返回文件路径(这是正确且有效的 ASCII 文件)。我永远不会到达第二个 AfxMessageBox,因为 getline 会产生:

Unhandled exception at 0x000007FEF7B4AAEE (msvcp110.dll) in program.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

vs11 将我重定向到 xiosbase 第 443 行

    locale __CLR_OR_THIS_CALL getloc() const
{ // get locale
return (*_Ploc);/*THIS IS LINE 443*/
}

对于项目属性,我正在使用“在共享 dll 中使用 MFC”和“多线程 DLL”以及子系统“Windows”

额外的程序代码和包括:

#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);
}
}
}

有人知道出了什么问题吗?

最佳答案

我现在用VS10解决了这个问题。该算法可以正常工作。但我认为这不是解决方案!

它在同一台 PC 上与 vs10 一起工作也告诉我这不是 PC 的问题。

关于c++ - Getline 错误 MFC vs2012 (msvcp110.dll),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13451055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com