📄 c61.cpp
字号:
// c61.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <strstrea.h>
const int SIZE = 9;
// --------------------------------------------------------------------------
class Plot
{
friend ostream& operator<<( ostream& stream, Plot o );
public:
Plot( int i, int j )
{
if ( i > SIZE ) i = SIZE;
if ( i < 0 ) i = 0;
if ( j > SIZE ) j = SIZE;
if ( j < 0 ) j = 0;
x = i;
y = j;
}
private:
int x, y;
};
// --------------------------------------------------------------------------
ostream& operator<<( ostream& stream, Plot o )
{
for ( int j = SIZE; j >= 0; j-- )
{
stream << j;
if ( j == o.y )
{
for ( int i = 0; i < 2 * o.x - 1; i++ )
stream << " ";
stream << '*';
}
if ( j == 0 )
break;
stream << endl;
}
for ( int i = 1; i <= SIZE; i++ )
stream << " " << i;
stream << endl;
return stream;
}
// --------------------------------------------------------------------------
int main(int argc, char* argv[])
{
Plot a(2, 3), b(6, 4);
// ------------------------------------
cout << "Output using cout:\n";
cout << a << endl << b << endl;
// ------------------------------------
char str[200];
ostrstream outs( str, sizeof(str) );
outs << a << endl << b << endl;
outs << '\0';
cout << "Output using in - RAM formatting:\n";
cout << str;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -