C++?????????????????????????
?????????? ???????[ 2016/9/12 14:37:42 ] ??????????????????? C++
????1?????????
????iomanip ?????????I/O??????????????
????stdiostream ?????????C??C + +??I/O?????????????C????????C++????
????2?????й??
????ios??????????????????istream???ostream?? iostream??????????????????iostream?????istream???ostream??????????ж?????????
??????ifstream???????istream????ofstream???????ostream????fstream????? ??iostream
????iostream??????4????????
????1????“cout<<”???????????????????????????????????????????????ж??????????
???????????????????????????????????????????????????????????????????????
?????????C????????prinf????????????????????????????????????????????????鷳?????????????
????2??cout????????ж?????????????????????????????е??????????cout???? ?????endl???
????????????????????????????????????????????????????????з??? ?????????????????????
????????????????????з?”
“????cout<<a<<“
”??????????????У????????cout ??(???????????б?????????????????????
????3????iostream?????”<<“??”>>”????????????????????????????????????????δ??????????????????????????? ?????????
?????????????????μ?????????????”<<“??”>>”??????????????????????????????????????????
????cout ?????????????????????????????????? ????????????????cerr???е?????????????????
????cerr???????????????????????????????й????????clog?е???????????????У??????????????endl???????????
????3??????????? cin
???????????????
????cin.get() //?????????????????????
????cin.get(???????) //?????????????????洢??ch
????cin.get(????????) //???????????
????cin.get(????????) //??????????
????cin.getline()
????cin.ignore() //??????????????????
????cin.peek() //???????????????????????????????????
????cin.putback() //?????????????????
???????
????1?????cin???????ж???????????????????????????ζ??????????μ?
????2????????????????EOF??????????????????????????????????е?????????????????????????
???????
????1???????????????????????????
????2???ж????е??????????????????????????
????3???????ж??10???????
????4???????к???5???????????10???????
????5????????μ????????????????????????
#include <iostream>
using namespace std;
int main()
{
char ch1;
int look;
char str1[11] = {0};
char str2[11] = {0};
char str3[100] = {0};
//???????????????????????
ch1 = cin.get();
cin.putback(ch1);
//?ж????е????????????????????????
look = cin.peek();
if(look == (int)ch1)
{
cout<<"cin.peek()???????????????λ??"<<endl;
}
else
{
cout<<"cin.peek()???????????????????λ??"<<endl;
}
//?????ж??10?????
cin.get(str1??11);
//?????к???5???????????10?????
cin.ignore(5);
cin.get(str2??11??EOF);
//??????μ????????????????????????
cin.getline(str3??100);
//?????????????
cout<<"????????"<<ch1<<endl;
cout<<"????? ???????"<<str1<<endl;
cout<<"????? ???????"<<str2<<endl;
cout<<"??μ????????"<<str3<<endl;
system("pause");
return 0;
}
?????????
????0123456789abcde9876543210zzzzzzzzzzxxxxxxxxxxxxxyyyyyyyyyyyy
????cin.peek()???????????????λ??
????????????0
????????? ???????0123456789
????????? ???????9876543210
??????μ????????zzzzzzzzzzxxxxxxxxxxxxxyyyyyyyyyyyy
????4?????????? cout
?????????????
????cout.flush() //????????
????cout.put() //?????д??????
????cout.write() //???????д??????????
????eg : cout.setf( ios::dec );
????cout.setf(ios::hex??ios::basefield)????????????????
?????????
????1??fmtflags setf( fmtflags flags ); ????????????????????????cout.unself()????????????????μ??
????2??fmtflags setf( fmtflags flags?? fmtflags needed ); ?????????????????????????????????????????????????ios_base::basefield???????????п?????
???????????????<iomanip>
????eg: cout<<setw(5);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11