读取字符串字符时出错

Error reading the character of a string

本文关键字:出错 字符 字符串 读取      更新时间:2023-10-16
#include <algorithm>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "kcftracker.hpp"
#include <dirent.h>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]){
if (argc > 5) return -1;
bool HOG = true;
bool FIXEDWINDOW = false;
bool MULTISCALE = true;
bool SILENT = true;
bool LAB = false;
for(int i = 0; i < argc; i++){
if ( strcmp (argv[i], "hog") == 0 )
HOG = true;
if ( strcmp (argv[i], "fixed_window") == 0 )
FIXEDWINDOW = true;
if ( strcmp (argv[i], "singlescale") == 0 )
MULTISCALE = false;
if ( strcmp (argv[i], "show") == 0 )
SILENT = false;
if ( strcmp (argv[i], "lab") == 0 ){
LAB = true;
HOG = true;
}
if ( strcmp (argv[i], "gray") == 0 )
HOG = false;
}
// Create KCFTracker object
KCFTracker tracker(HOG, FIXEDWINDOW, MULTISCALE, LAB);
// Frame readed
Mat frame;
// Tracker results
Rect result;
// Path to list.txt
ifstream listFile;
string fileName = "C:\UsersPeterLinDocumentsVisual Studio 2015ProjectsProject7x64Debugballimages.txt";
listFile.open(fileName);

每次我运行此代码时,系统都会告诉我读取字符串时出错,无法获取文件名。我想知道原因。

您没有正确转义 \。

如果逃避它们太痛苦了,它们通常可以,您可以尝试使用逐字字符串文字。 用作前缀,它要求编译器忽略转义字符。编写正则表达式时非常有用。

在这里阅读: http://stroustrup.com/C++11FAQ.html#raw-strings