读取字符串字符时出错

时间:2017-07-12 18:59:47

标签: c++

#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:\\Users\PeterLin\Documents\Visual Studio 2015\Projects\Project7\x64\Debug\ball\images.txt";
    listFile.open(fileName);

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

1 个答案:

答案 0 :(得分:0)

你没有正确地逃脱\。

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

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