코드 4-14 파일에 데이터 저장하기 [ch04/storage]
01 // String filename = "mydata.xml"; 02 // String filename = "mydata.yml"; 03 String filename = "mydata.json"; 04 05 void writeData() 06 { 07 String name = "Jane"; 08 int age = 10; 09 Point pt1(100, 200); 10 vector<int> scores = { 80, 90, 50 }; 11 Mat mat1 = (Mat_<float>(2, 2) << 1.0f, 1.5f, 2.0f, 3.2f); 12 13 FileStorage fs(filename, FileStorage::WRITE); 14 15 if (!fs.isOpened()) { 16 cerr << "File open failed!" << endl; 17 return; 18 } 19 20 fs << "name" << name; 21 fs << "age" << age; 22 fs << "point" << pt1; 23 fs << "scores" << scores; 24 fs << "data" << mat1; 25 26 fs.release(); 27 }