看看学习{:7_172:}
强烈支持楼主ing……水军路过。。。
看看
新手
#include<iostream>
clss t
{
t() {std::cout << "Initalize" << std::endl;}
~t() {std::cout << "Clean up" << std::endl;}
} st;
int main()
{
std::cout << "Hello,world!\n";
}
骗骗人
看看
柠“萌”圆 发表于 2014-3-8 20:59
在百度贴吧C++吧的一位吧友又给出了一个解答,比我的简练......
没有最后的clean up 这一句呀
你这程序有问题,我帮你修改了一下。就是一个重载<<运算符。#include <cstdio> // 可以修改头文件
namespace std { // 自定义std命名空间
class io { // 自定义io类
public:
friend io& operator<<(io& os, char* str);
};
io& operator<<(io& os, char* str) {
printf("Initialize\n");
printf("%s", str);
printf("Clean up\n");
return os;
}
io cout; // 命名一个变量叫cout(由于cout不是关键字,我也没有包含iostream库,所以不是错的)
}
int main()
{
std::cout << "Hello, world!\n";
}
看一下。是不是构造一个对象就行了。
{:9_240:}
支持
{:1_1:}