// ============================================================================ // p1c08_02 — 8.4.1 字符输出 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; #include // --- 原文片段 [58954476:1] 8.4.1 字符输出 --- //cout.flush 刷新缓冲区,linux下有效 void test01(){ cout << "hello world"; //刷新缓冲区 cout.flush(); } //cout.put 输出一个字符 void test02(){ cout.put('a'); //链式编程 cout.put('h').put('e').put('l'); } //cout.write 输出字符串 buf,输出多少个 void test03(){ //char* str = "hello world!"; //cout.write(str, strlen(str)); char* str = "*************"; for (int i = 1; i <= strlen(str); i ++){ cout.write(str, i); cout << endl; } for (int i = strlen(str); i > 0; i --){ cout.write(str, i); cout << endl; } } // --- main --- int main() { test01(); test02(); test03(); return 0; }