// ============================================================================ // p1c09_03_01 — 3.1.2.9 string和c-style字符串转换 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954488:0] 3.1.2.9 string和c-style字符串转换 --- static void block_0() { string s = "abcdefg"; char& a = s[2]; char& b = s[3]; a = '1'; b = '2'; cout << s << endl; cout << (int*)s.c_str() << endl; s = "pppppppppppppppppppppppp"; //a = '1'; //b = '2'; cout << s << endl; cout << (int*)s.c_str() << endl; } // --- main --- int main() { block_0(); return 0; }