测试一下这地方如何?
来源:互联网 发布:ac990会计核算软件 编辑:程序博客网 时间:2024/05/16 16:00
时过境迁,很多C++的基础知识有些生疏了,这会拿来重温一下一上来就发现输入输出好多忘了,想想前段时间拿CString和std::string混用来实字符串转换,感觉比较可笑,其实C++中很轻松就能实现转换.
一、作用域和字符串格式化的例子,后面会不断补充
#include <Windows.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class A
...{
public:
A()...{
cout<<"构造函数"<<endl;
}
~A()
...{
cout<<"析构函数"<<endl;
}
A(int m, int d):month(m),day(d)...{};
int getMonth()
...{
return month;
}
int getDay()
...{
return day;
}
protected:
private:
int month;
int day;
};
int _tmain(int argc, _TCHAR* argv[])
...{
if (1)
...{
A a;
}
//上面的a此时已经脱离作用域了,所以发生了析构
A b(9,12);
ostringstream f;
f.fill('0');
f<<setw(2)<<b.getMonth()<<"-"<<setw(2)<<b.getDay();
char buf[100];
cin>>buf;
cout<<"buf:="<<buf<<endl;
f<<endl<<setw(4)<<strlen(buf)<<buf<<endl;
string str = f.str();
cout<<str<<endl;
cout<<"end of main"<<endl;
//b则在退出之前发生析构
return 0;
}
一、作用域和字符串格式化的例子,后面会不断补充
#include <Windows.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class A
...{
public:
A()...{
cout<<"构造函数"<<endl;
}
~A()
...{
cout<<"析构函数"<<endl;
}
A(int m, int d):month(m),day(d)...{};
int getMonth()
...{
return month;
}
int getDay()
...{
return day;
}
protected:
private:
int month;
int day;
};
int _tmain(int argc, _TCHAR* argv[])
...{
if (1)
...{
A a;
}
//上面的a此时已经脱离作用域了,所以发生了析构
A b(9,12);
ostringstream f;
f.fill('0');
f<<setw(2)<<b.getMonth()<<"-"<<setw(2)<<b.getDay();
char buf[100];
cin>>buf;
cout<<"buf:="<<buf<<endl;
f<<endl<<setw(4)<<strlen(buf)<<buf<<endl;
string str = f.str();
cout<<str<<endl;
cout<<"end of main"<<endl;
//b则在退出之前发生析构
return 0;
}
- 测试一下这地方如何?
- 测试一下,看看如何???
- 测试一下 CSDN 的 blog 如何
- 测试一下测试一下测试一下
- 测试一下测试一下测试一下
- 测试一下测试一下测试一下
- 测试一下 一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下
- 测试一下。
- 测试一下
- 测试一下
- Google发布Google Trends(谷歌趋势)中文版
- 搞笑及拍砖神功集粹
- 我们为什么要推出ASP.NET栏目?
- Linux下文本编辑器
- Development Principles
- 测试一下这地方如何?
- 关于ASP.Net中的时间处理
- 初学LINUX一些常用命令
- Java学习笔记之SWING -- 基本SWING程序(地图编辑器框架大致效果完成)
- 在 ASP.NET 中执行 URL 重写
- 8月19日BBUG:电信技术开发经验分享与前景展望
- 吵架的代价
- 无线技术,正在改变着这个世界
- 细说HTML元素的ID和Name属性的区别 (转)