FileStorage Read String Start With Number Need Quotation Mark가 숫자로 시작하는 문자열을 읽으려면 따옴표가 필요합니다.
2969 단어 start with
// 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.