物向导向的精髓 多型与虚拟 chapter 1

int _tmain(int argc, _TCHAR* _targc[])
{
	cout<<"all your keyboard input in monitor"
		<<"will into copy.txt. \n"
		<<"terminate by ^z\n\n";
	
	ofstream outFile("copy.txt");
	if(!outFile){
		cout<<"can't open copy.txt for output"<<endl;
		return -1;
	}

	char c;
	while (cin.get(c))
		outFile.put(c);

	return 0;
}
int _tmain(int argc, _TCHAR* _targc[])
{
	cout<<"all your keyboard input in monitor"
		<<"will into copy.txt. \n"
		<<"terminate by ^z\n\n";
	
	ifstream inFile("copy.txt");
	if(!inFile){
		cout<<"can't open copy.txt for output"<<endl;
		return -1;
	}

	char c;
	while (inFile.get(c))
		cout.put(c);

	return 0;
}

输入 & 读取

/////////////////////////////////////////////////////////////////////////////////////////////////


struct 和 class 的差异:

class member 的预设封装层级是private,而struct members的预设对撞层级是public

如果你有特别指定,struct和class两者可以彼此完全取代,如:

struct CPoint{
public:
   CPoint (float x = 0.0;) : _x (x) {}

   float x() {return _x;}
   void x(float xval) { _x = xval;}
protected:
   float _x;
};

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页