標準輸入流物件cin,重點掌握的函式:
cout.flush()//重繪緩沖區
cout.put()//向緩沖區寫字符
cout.write()//二進制流的輸出
cout.width()//輸出格式控制
cout.fill()
cout.set(標記)
cout.flush()
代碼如下:
#include <iostream>
using namespace std;
void test01()
{
cout << "hello world";
cout.flush();
}
int main()
{
test01();
return 0;
}
cout.put()
代碼如下:
#include <iostream>
using namespace std;
void test01()
{
cout << "hello world";
cout.put('h').put('e').put('l') << endl;
}
int main()
{
test01();
return 0;
}
測驗結果:

cout.write()
代碼如下:
#include <iostream>
using namespace std;
void test01()
{
cout << "hello world"<<endl;
cout.write("hello zhaosi", strlen("hello zhaosi"));
}
int main()
{
test01();
return 0;
}
測驗結果:

cout.width()//輸出格式控制
cout.fill()
cout.set(標記)
代碼如下:
#include <iostream>
#include <iomanip>
using namespace std;
void test01()
{
//成員方法的方式
int number = 10;
cout << number << endl;
cout.unsetf(ios::dec);//卸載當前默認的10進制輸出方式
cout.setf(ios::oct);//八進制輸出
cout.setf(ios::showbase);
cout << number << endl;
cout.unsetf(ios::oct);//卸載8進制
cout.setf(ios::hex);//16進制輸出
cout << number << endl;
cout.width(10);
cout.fill('*');
cout.setf(ios::left);
cout << number << endl;
//通過控制符
int number2 = 10;
cout << hex
<< setiosflags(ios::showbase)
<< setw(10)
<< setfill('*')
<< setiosflags(ios::left)
<< number2
<< endl;
}
int main()
{
test01();
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/287507.html
標籤:其他
上一篇:Camera:高斯模糊
下一篇:安卓的相對布局與線性布局
