This shows you the differences between two versions of the page.
— |
prog:dev_cpp:250804-01:index [2025/08/04 14:27] (current) jethro created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~NOTOC~~ | ||
+ | ====== C++ string append方法的常用用法 (2025-08-04) ====== | ||
+ | * Source: [[https://blog.csdn.net/air_wswn/article/details/7785739]] | ||
+ | * {{:prog:dev_cpp:250804-01:pasted:20250804-142532.png?300}} | ||
+ | ===== Local Backup ===== | ||
+ | * C++ string append()新增文本 | ||
+ | * 使用append()加入文字常用方法: | ||
+ | * 直接添加另一個完整的字串: | ||
+ | * 如str1.append(str2); | ||
+ | * 新增另一個字串的某一段子字串: | ||
+ | * 如str1.append(str2, 11, 7); | ||
+ | * 添加幾個相同的字元: | ||
+ | * 如str1.append(5, '.'); | ||
+ | * 注意,個數在前字符在後.上面的代碼意思為在str1後面添加5個".". | ||
+ | * <sxh c++> | ||
+ | //======================================== | ||
+ | #include<iostream> | ||
+ | using namespace std; | ||
+ | //======================================== | ||
+ | int main() | ||
+ | { | ||
+ | string str1="I like C++"; | ||
+ | string str2=",I like the world."; | ||
+ | string str3="Hello"; | ||
+ | string str4("Hi"); | ||
+ | //==================================== | ||
+ | str1.append(str2); | ||
+ | str3.append(str2, 11, 7); | ||
+ | str4.append(5, '.'); | ||
+ | //==================================== | ||
+ | cout<<str1<<endl; | ||
+ | cout<<str3<<endl; | ||
+ | cout<<str4<<endl; | ||
+ | system("pause"); | ||
+ | return 0; | ||
+ | } | ||
+ | //========================================</sxh> | ||
+ | * 運行結果為<sxh>I like C++,I like the world. | ||
+ | Hello World. | ||
+ | Hi.....</sxh> | ||
+ | ====== ====== | ||
+ | [[:prog:index|Back]] | ||
+ | ====== ====== | ||
+ | <html> | ||
+ | <!-- | ||
+ | PDF for A4-Portrait: {{pdfjs 50%,450px > xxx.pdf?page-fit}} | ||
+ | PDF for A4-Landscape: {{pdfjs 700px,500px > xxx.pdf?page-fit}} | ||
+ | PDF for iPad Note: {{pdfjs 700px,500px > xxx.pdf?page-fit}} | ||
+ | |||
+ | {{gallery>work-note:2024-08:12?lightbox&0&150x150&crop}} | ||
+ | |||
+ | Youtube: {{youtube>large:XXXXX}} | ||
+ | Code Highlight: <sxh php; first-line: 70; highlight: [89,92]; title: New title attribute in action> | ||
+ | |||
+ | --> | ||
+ | </html> | ||