- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在行:std::ifstream fileOpen(file.c_str());
在下面的函数中程序崩溃并给我这个错误:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
Process exited with return value 3
然而,在 Debug模式下,整个程序运行,但在主函数的 return 0 语句中我得到
Program received signal SIGTRAP, Trace/breakpoint trap.
我在 Windows 7 上使用 Orwell Dev/C++。据我所知,第一个问题是抛出但未捕获的异常(我还没有自学异常,所以我不知道该怎么做,但我可以阅读)并且它可能会破坏堆栈。后一个错误我无法获得更多具体信息。谁能指出解决方案的方向?哦,还有,该函数在第四次崩溃之前被调用了三次。
//Get a line of data from a file
std::string getData( std::string file, int line )
{
std::string data;
std::ifstream fileOpen(file.c_str());
if (fileOpen.is_open())
{
if( fileOpen.good() )
{
for( int lineno = 0; getline(fileOpen,data) && lineno < line; lineno ++ )
{
if( lineno != line )
{
data = "";
}
}
}
fileOpen.close();
}
return data;
}
//Parse comma delimited string into a vector
void parseData( std::vector<double> &temp, std::string data )
{
std::istringstream ss(data);
std::string token;
while(std::getline(ss, token, ','))
{
temp.push_back(atoi(token.c_str()));
}
}
这些是通过这样的代码调用的:
std::string instData = getData( levelName+".dat", 2 );
if( instData != "" )
{
parseData( temp, instData );
instances.resize(temp.size() / 4);
j = 0;
for( int i = 0; i < temp.size(); i += 4 )
{
instances[ j ].type = temp[ i ];
instances[ j ].xPos = temp[ i + 1 ];
instances[ j ].yPos = temp[ i + 2 ];
instances[ j ].zIndex = temp[ i + 3 ];
j ++;
}
temp.clear();
}
此代码本身是一个函数的一部分,该函数旨在用指定文件中的数据填充各种 vector 。不过,其中的其余代码与上面的基本相同。
最佳答案
我可以清楚地看到这里的问题:
instances[ j ].xPos = temp[ i + 1 ];
instances[ j ].yPos = temp[ i + 2 ];
instances[ j ].zIndex = temp[ i + 3 ];
当 i == temp.size() - 3
时,最后一条语句将访问内存区域 1,超出为 temp
分配的内存末尾,导致 Undefined Behavior .发生这种情况后,您的程序就进入了无效状态。
在打开文件的那一行出现错误可能只是未定义行为的影响之一。作为测试,删除上面三行并查看是否发生任何运行时错误。
关于c++ - ifstream fileOpen 导致程序到 'terminate in an unusual way',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456620/
在 android 5.0 设备上,我有一个问题,即下载的文件无法cordova fileopener pluginnorInAppBrowsernor file:///data/data/myapp
使用 Cordova FileOpener2 ,以及许多其他插件,例如 Cordova File、Cordova FileTransfer.. 我在 Android 中找不到我的本地 PDF 位置。
我正在寻找定制类似于 Vista 的 OpenFileDialog使用自定义 WinForms 和 WPF 控件。我知道你可以模板 XP-like OpenFileDialog但这看起来很丑陋,不能满
我正在使用 Windows Phone 8.1 相册应用程序,我想在相册中存储超过 100 张图像,但文件打开选择器无法处理超过 5-6 张图像是否可以使用路径访问图像或将图像源设置为手机存储?这是将
我正在尝试让 MT4 与 Ubuntu 对话;代码: volumeCount=FileOpen(/home/david/.wine/drive_c/Program\ Files\ \ (x86\)/C
通过 Selenium,我成功地实现了网站任务的自动化。但是我遇到了一个问题:我需要在提交表单之前将文件上传到我的网页。将上传的文件写入其输入元素不是一种选择,因为它比这更复杂。所以基本上我需要通过单
这是我的代码: import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; im
在行:std::ifstream fileOpen(file.c_str()); 在下面的函数中程序崩溃并给我这个错误: This application has requested the Runt
我已经下载了插件FileOpener 并添加到 m,y 项目中,如下所示: sample
我正在使用 plist 文件以允许我的 Qt 应用程序能够直接从查找器打开文件。不幸的是,有时在某些系统上(如下所述)应用程序崩溃/卡住。 此问题仅在某些客户端计算机上出现,并且仅当我在使用 10.6
我使用的是 VS2010 和 Windows 7,我的应用程序是 SDI 共享 DLL,从 VC6 升级而来。安装我的应用程序后,如果用户双击已注册的文件类型,应用程序会在 MFC 函数处崩溃: vo
我试图在 Inno Setup 代码中使用 FileOpen,但是 Inno Setup 编译器一直向我抛出以下错误。 Unknown Identifier 'FileOpen' 这是一个示例代码:
我有一个表,其中包含三列 表名是 BFILETABEL FILEID (number) //number data type FILENAME (varchar2) FILEDATA (BFILE)
在我的 Ionic 5 项目中,我将 PDF 下载到设备(物理 iPhone Pro、iOS 模拟器以及 Android 设备)。转换为 Base64 并存储为 .txt 文件。我正在检索文件如下:
我是一名优秀的程序员,十分优秀!