日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++ Primer 5th笔记(chap 13 拷贝控制) 实例2内存管理测试结果

發(fā)布時(shí)間:2025/3/21 c/c++ 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ Primer 5th笔记(chap 13 拷贝控制) 实例2内存管理测试结果 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 測試代碼

string temp[] = { "one", "two", "three" };StrVec sv(begin(temp), end(temp));// run the string empty funciton on the first element in svif (!sv[0].empty())sv[0] = "None"; // assign a new value to the first string // we'll call getVec a couple of times// and will read the same file each timeifstream in("D:/code/cprimerGit/cplusprimer/cprimer/data/strvec-storyDataFile");//ifstream in("../data/strvec-storyDataFile");StrVec svec = getVec(in);print(svec);in.close();cout << "copy " << svec.size() << endl;auto svec2 = svec;print(svec2);cout << "assign" << endl;StrVec svec3;svec3 = svec2;print(svec3);StrVec v1, v2;v1 = v2; // v2 is an lvalue; copy assignmentin.open("D:/code/cprimerGit/cplusprimer/cprimer/data/strvec-storyDataFile");v2 = getVec(in); // getVec(in) is an rvalue; move assignmentin.close();StrVec vec; // empty StrVecstring s = "some string or another";vec.push_back(s); // calls push_back(const string&)vec.push_back("done"); // calls push_back(string&&)// emplace member covered in chpater 16s = "the end"; #ifdef VARIADICSvec.emplace_back(10, 'c'); // adds cccccccccc as a new last elementvec.emplace_back(s); // uses the string copy constructor #elsevec.push_back(string(10, 'c')); // calls push_back(string&&)vec.push_back(s); // calls push_back(const string&) #endifstring s1 = "the beginning", s2 = s; #ifdef VARIADICSvec.emplace_back(s1 + s2); // uses the move constructor #elsevec.push_back(string(s1 + s2)); // calls push_back(string&&) #endif

2. strvec-storyDataFile文件內(nèi)容:

Alice Emma has long flowing red hair. Her Daddy says when the wind blows through her hair, it looks almost alive, like a fiery bird in flight. A beautiful fiery bird, he tells her, magical but untamed. "Daddy, shush, there is no such thing," she tells him, at the same time wanting him to tell her more. Shyly, she asks, "I mean, Daddy, is there?"

3. 輸出結(jié)果:


【參考】

[1] 代碼copyControl.h

總結(jié)

以上是生活随笔為你收集整理的C++ Primer 5th笔记(chap 13 拷贝控制) 实例2内存管理测试结果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。