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.

本文转自博客园Grandyang的博客,原文链接:读取数字开头的字符串需要加引号FileStorage Read String Start With Number Need Quotation Mark ,如需转载请自行联系原博主。

相关文章
|
1月前
|
存储 缓存 测试技术
CMake String函数:如何巧妙地在cmake中操作字符串
CMake String函数:如何巧妙地在cmake中操作字符串
84 0
|
3月前
|
存储 编译器 Linux
【字符串探秘:手工雕刻的String类模拟实现大揭秘】(下)
【字符串探秘:手工雕刻的String类模拟实现大揭秘】
|
3月前
|
编译器 C语言 C++
【字符串探秘:手工雕刻的String类模拟实现大揭秘】(中)
【字符串探秘:手工雕刻的String类模拟实现大揭秘】
|
3月前
|
存储 编译器
【字符串探秘:手工雕刻的String类模拟实现大揭秘】(上)
【字符串探秘:手工雕刻的String类模拟实现大揭秘】
|
3月前
String字符串类型时间比较(根据时间判断返回 ‘已结束’或‘进行中‘’)
String字符串类型时间比较(根据时间判断返回 ‘已结束’或‘进行中‘’)
23 1
|
2月前
|
存储 XML 缓存
Java字符串内幕:String、StringBuffer和StringBuilder的奥秘
Java字符串内幕:String、StringBuffer和StringBuilder的奥秘
26 0
|
3月前
|
C++
c++:string相关的oj题(把字符串转换成整数、344.反转字符串、387. 字符串中的第一个唯一字符、917. 仅仅反转字母)
c++:string相关的oj题(把字符串转换成整数、344.反转字符串、387. 字符串中的第一个唯一字符、917. 仅仅反转字母)
54 0
|
3月前
|
C++ 索引
c++:string相关的oj题(415. 字符串相加、125. 验证回文串、541. 反转字符串 II、557. 反转字符串中的单词 III)
c++:string相关的oj题(415. 字符串相加、125. 验证回文串、541. 反转字符串 II、557. 反转字符串中的单词 III)
42 0
|
存储 编译器 Linux
标准库中的string类(中)+仅仅反转字母+字符串中的第一个唯一字符+字符串相加——“C++”“Leetcode每日一题”
标准库中的string类(中)+仅仅反转字母+字符串中的第一个唯一字符+字符串相加——“C++”“Leetcode每日一题”
|
14天前
|
JavaScript
js 字符串String转对象Object
该代码示例展示了如何将一个以逗号分隔的字符串(`&#39;1.2,2,3,4,5&#39;`)转换为对象数组。通过使用`split(&#39;,&#39;)`分割字符串并`map(parseFloat)`处理每个元素,将字符串转换成浮点数数组,最终得到一个对象数组,其类型为`object`。