zoukankan      html  css  js  c++  java
  • FileStorage Read String Start With Number Need Quotation Mark 读取数字开头的字符串需要加引号

        // Write data
        FileStorage fs("test.yml", FileStorage::WRITE);
        fs << "MyString" << "123abc";
        fs.release();
    
        // Read data
        FileStorage fs2("test.yml", FileStorage::READ);
        string str = fs2["MyString"];
        cout << "MyString = " << str << endl;
        fs2.release();

    In OpenCV, the FileStorage class can read and write data in the file. If you write the string "123abc" into the file, it will shows with quotation mark in the file. Now I want to read this string from the file into a string variable, you need to keep the quotation mark in the file which should be see as follows:

    MyString: "123abc"

    Now it can be read without problem, but if you change it to the followings:

    MyString: 123abc

    This will not gonna work this time, but if the string is not start with a number, it will work. I might treat it as a bug in the OpenCV. The three different situation is as follows:

    MyString: "123abc"    // Work
    MyString: 123abc      // NOT work
    MyString: abc123      // Work

    In sum, when you want to read a string into a variable, if it starts with a number, you need to add the quotation marker to the whole string in the file.

  • 相关阅读:
    卡特兰数列(蒟蒻的学习笔记)
    10月7日 蒟蒻的流水账
    10月6日 蒟蒻的流水账
    10月5日 蒟蒻的流水账
    10月4号 蒟蒻的流水账
    2017 10 14(吐槽初赛)
    2017 10 13
    个人介绍
    luogu P1156 垃圾陷阱
    模板之矩阵快速幂(luogu P3390【模板】矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/grandyang/p/4480803.html
Copyright © 2011-2022 走看看