1.输出布尔数据
2.输出整型数据
3.输出浮点数
4.取消省略空白符
5.istringstream使用
6.ostringstream使用
7.读取文件
8.写入文件
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int main() {
bool falg = false;
cout << "falg="<< falg <<endl;
cout << "falg=="<< boolalpha << falg <<endl;
cout << showbase;
cout << "十进制"<< dec << 9 << endl;
cout << "八进制"<< oct << 9 << endl;
cout << "十六进制"<< hex << 12 << endl;
cout << noshowbase;
double PI = 3.14159265358979323846;
cout.precision(3);
cout << "pi="<< PI << endl;
cout << setprecision(5) << "pi=="<< PI << endl;
float f = 13.10000;
cout << showpoint << "f="<<f << noshowpoint << endl;
cin >> noskipws;
char c;
cout << "请输入字符: " << endl;
cin >> c;
cout << c;
cin >> skipws;
string s1 = "abc def";
istringstream stream(s1);
string s2;
while (stream >>s2){
cout << s2 << endl;
}
int aa = 5;
double bb = 3.142351;
string str = "";
ostringstream oss;
oss << aa << "---"<< bb;
str = oss.str();
cout << str << endl;
fstream file("D:\\CLionProjects\\Mytest\\day07\\04_do_io\\a.txt",ios::in);
if(file.is_open()){
string line;
while (getline(file,line)){
cout<< line <<endl;
}
file.close();
}else{
cout<< "文件无法打开"<<endl;
}
fstream file2{"D:\\CLionProjects\\Mytest\\day07\\04_do_io\\a2.txt",ios::app};
if(file2.is_open()){
cout<< "正常打开文件"<<endl;
file2 << ",ni hao";
file2 << endl;
file2.close();
}else{
cout<< "无法正常打开文件"<< endl;
}
return 0;
}