【发布时间】:2018-12-16 14:14:17
【问题描述】:
当我尝试在调试模式下运行代码时,一切正常,但是当我尝试在发布模式下运行它时,我收到错误“file_name!= nullptr”(错误来自 fopen)。我知道错误的含义,但我不知道为什么会收到错误以及如何修复它
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
String imageName("C:/Users/x/Desktop/pic.png"); // by default
if (argc > 1)
{
imageName = argv[1];
}
Mat image;
image = imread(imageName, IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
错误信息:
>-----------Microsoft Visual C++ Runtime Library----------------
>
>
>Debug Assertion Assertion Faild!
>
>Programm: C:\Users\x\...\myProgramm.exe
>File: minkernel\crts\ucrt\src\appcrt\stdio\fopen.cpp
>
>Line: 30
>
>Expression: file_name != nullptr
【问题讨论】:
-
应该是字符串,不是字符串,不是吗?同样在 MSVC 命令行参数中,IDE 界面中的 Release/Debug 参数是不同的。
-
字符串不起作用。我不使用命令行参数,我使用默认的 imageName 值
-
Windows 中的路径分隔符是反斜杠。您正在使用正斜杠。这可能有效,也可能无效。
-
我用反斜杠试过了,但它不起作用。
-
@Trifik 用反斜杠替换时,需要加两个来转义反斜杠
C:\\Users\\x\\Desktop\\pic.png(只需确认已完成)
标签: c++ windows visual-c++ c++17