本文實(shí)例為大家分享了C++實(shí)現(xiàn)數(shù)據(jù)文件存儲(chǔ)與加載的具體代碼,供大家參考,具體內(nèi)容如下
主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、成都響應(yīng)式網(wǎng)站建設(shè)公司、程序開發(fā)、微網(wǎng)站、小程序開發(fā)等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體,具備承接不同規(guī)模與類型的建設(shè)項(xiàng)目的能力。
首先請(qǐng)先確認(rèn)已經(jīng)安裝好了opencv3及以上版本。
#include <opencv2/opencv.hpp> #include <iostream> #include <string> using namespace cv; using namespace std;
存儲(chǔ)
then
int main() { //創(chuàng)造一些要存的數(shù)據(jù)先 string words = "hello, my guys!"; float n = 3.1415926; Mat m = Mat::eye(3, 3, CV_32F); //開始創(chuàng)建存儲(chǔ)器 FileStorage save("data.yml", FileStorage::WRITE);// 你也可以使用xml格式 save << "words" << words; save << "number" << n; save << "matrix" << m; save.release(); //存儲(chǔ)完畢 cout << "finish storing" << endl;
加載
//加載數(shù)據(jù),類似Python字典的用法,創(chuàng)建加載器 FileStorage load("data.yml", FileStorage::READ); float nn; Mat mm; string ww; load["words"] >> ww; load["number"] >> nn; load["matrix"] >> mm; cout<< ww << endl << nn << endl << mm; cout << endl << "That's the end"; load.release(); return 0; }
完整代碼
#include <opencv2/opencv.hpp> #include <iostream> #include <string> using namespace cv; using namespace std; int main() { string words = "hello, my guys!"; float n = 3.1415926; Mat m = Mat::eye(3, 3, CV_32F); FileStorage save("data.yml", FileStorage::WRITE); save << "words" << words; save << "number" << n; save << "matrix" << m; save.release(); cout << "finish storing" << endl; FileStorage load("data.yml", FileStorage::READ); float nn; Mat mm; string ww; load["words"] >> ww; load["number"] >> nn; load["matrix"] >> mm; cout<< ww << endl << nn << endl << mm; cout << endl << "That's the end"; load.release(); return 0; }
演示結(jié)果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站標(biāo)題:C++實(shí)現(xiàn)數(shù)據(jù)文件存儲(chǔ)與加載
文章路徑:http://chinadenli.net/article32/poojsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、面包屑導(dǎo)航、App設(shè)計(jì)、網(wǎng)站改版、小程序開發(fā)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)