欢迎来到天天文库
浏览记录
ID:44704195
大小:57.01 KB
页数:4页
时间:2019-10-25
《【C++】setw函数的用法和作用【原创技术】》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、作用:setw(4)是定义字段长度的函数用法://题目:结构体成员变量//作者:武叶//创作时间:2012年4月21日//使用语言:C++#include"iostream.h"#include"iomanip.h"structstudent{intnum;charname[20];charsex;intage;}stu={97001,"linlin",'F',19};voidmain(){cout<2、nclude"iomanip.h"才能使用setw函数定义字段长度这是iomanip.h的头文件内容:/****iomanip.h-definitions/declarationsforiostream'sparameterizedmanipulators**Copyright(c)1991-1997,MicrosoftCorporation.Allrightsreserved.**Purpose:*Thisfiledefinestheclasses,values,macros,andfunctions*usedbytheiostreamclasses'pa3、ramterizedmanipulators.*[AT&TC++]**[Public]*****/#if_MSC_VER>1000#pragmaonce#endif#ifdef__cplusplus#ifndef_INC_IOMANIP#define_INC_IOMANIP#if!defined(_WIN32)&&!defined(_MAC)#errorERROR:OnlyMacorWin32targetssupported!#endif#ifdef_MSC_VER//Currently,allMSCcompilersforWin32platformsdef4、aultto8byte//alignment.#pragmapack(push,8)#include#endif//_MSC_VER#include#ifdef_MSC_VER#pragmawarning(disable:4514)//disableunwanted/W4warning//#pragmawarning(default:4514)//usethistoreenable,ifnecessary#endif//_MSC_VER//#define__MKMANIP(X)#defineX##(T)__#5、#X##_##T//__MKMANIP(SMANIP);//__MKMANIP(SAPP);//__MKMANIP(IMANIP);//__MKMANIP(IAPP);//__MKMANIP(OMANIP);//__MKMANIP(OAPP);//__MKMANIP(IOMANIP);//__MKMANIP(IOAPP);#defineSMANIP(T)__SMANIP_##T#defineSAPP(T)__SAPP_##T#defineIMANIP(T)__IMANIP_##T#defineIAPP(T)__IAPP_##T#defineOMANIP(6、T)__OMANIP_##T#defineOAPP(T)__OAPP_##T#defineIOMANIP(T)__IOMANIP_##T#defineIOAPP(T)__IOAPP_##T#defineIOMANIPdeclare(T)classSMANIP(T){public:SMANIP(T)(ios&(*f)(ios&,T),Tt):_fp(f),_tp(t){}friendistream&operator>>(istream&s,constSMANIP(T)&sm){(*(sm._fp))(s,sm._tp);returns;}friend7、ostream&operator<<(ostream&s,constSMANIP(T)&sm){(*(sm._fp))(s,sm._tp);returns;}private:ios&(*_fp)(ios&,T);T_tp;};classSAPP(T){public:SAPP(T)(ios&(*f)(ios&,T)):_fp(f){}SMANIP(T)operator()(Tt){returnSMANIP(T)(_fp,t);}private:ios&(*_fp)(ios&,T);};classIMANIP(T){public:IM8、ANIP(T)(istream&(*f)(istre
2、nclude"iomanip.h"才能使用setw函数定义字段长度这是iomanip.h的头文件内容:/****iomanip.h-definitions/declarationsforiostream'sparameterizedmanipulators**Copyright(c)1991-1997,MicrosoftCorporation.Allrightsreserved.**Purpose:*Thisfiledefinestheclasses,values,macros,andfunctions*usedbytheiostreamclasses'pa
3、ramterizedmanipulators.*[AT&TC++]**[Public]*****/#if_MSC_VER>1000#pragmaonce#endif#ifdef__cplusplus#ifndef_INC_IOMANIP#define_INC_IOMANIP#if!defined(_WIN32)&&!defined(_MAC)#errorERROR:OnlyMacorWin32targetssupported!#endif#ifdef_MSC_VER//Currently,allMSCcompilersforWin32platformsdef
4、aultto8byte//alignment.#pragmapack(push,8)#include#endif//_MSC_VER#include#ifdef_MSC_VER#pragmawarning(disable:4514)//disableunwanted/W4warning//#pragmawarning(default:4514)//usethistoreenable,ifnecessary#endif//_MSC_VER//#define__MKMANIP(X)#defineX##(T)__#
5、#X##_##T//__MKMANIP(SMANIP);//__MKMANIP(SAPP);//__MKMANIP(IMANIP);//__MKMANIP(IAPP);//__MKMANIP(OMANIP);//__MKMANIP(OAPP);//__MKMANIP(IOMANIP);//__MKMANIP(IOAPP);#defineSMANIP(T)__SMANIP_##T#defineSAPP(T)__SAPP_##T#defineIMANIP(T)__IMANIP_##T#defineIAPP(T)__IAPP_##T#defineOMANIP(
6、T)__OMANIP_##T#defineOAPP(T)__OAPP_##T#defineIOMANIP(T)__IOMANIP_##T#defineIOAPP(T)__IOAPP_##T#defineIOMANIPdeclare(T)classSMANIP(T){public:SMANIP(T)(ios&(*f)(ios&,T),Tt):_fp(f),_tp(t){}friendistream&operator>>(istream&s,constSMANIP(T)&sm){(*(sm._fp))(s,sm._tp);returns;}friend
7、ostream&operator<<(ostream&s,constSMANIP(T)&sm){(*(sm._fp))(s,sm._tp);returns;}private:ios&(*_fp)(ios&,T);T_tp;};classSAPP(T){public:SAPP(T)(ios&(*f)(ios&,T)):_fp(f){}SMANIP(T)operator()(Tt){returnSMANIP(T)(_fp,t);}private:ios&(*_fp)(ios&,T);};classIMANIP(T){public:IM
8、ANIP(T)(istream&(*f)(istre
此文档下载收益归作者所有