main6.cpp
来自「c++ primer 经典书籍还有习题和答案,非常实用」· C++ 代码 · 共 53 行
CPP
53 行
// Section 15.6
// $ CC screen.cpp main6.cpp
/*
Screen Object ( 2, 5 )
Hello
World
*/
#include <iostream>
using std::cout;
#include <string>
using std::string;
#include "screen.h"
void printScreen( ScreenPtr &ps )
{
cout << "Screen Object ( "
<< ps->height() << ", "
<< ps->width() << " )\n\n";
for ( int ix = 1; ix <= ps->height(); ++ix )
{
for ( int iy = 1; iy <= ps->width(); ++iy )
cout << ps->get( ix, iy );
cout << "\n";
}
}
int main() {
Screen sobj( 2, 5 );
string init( "HelloWorld" );
ScreenPtr ps( sobj );
// Set the content of the screen
string::size_type initpos = 0;
for ( int ix = 1; ix <= ps->height(); ++ix )
for ( int iy = 1; iy <= ps->width(); ++iy )
{
ps->move( ix, iy );
ps->set( init[ initpos++ ] );
}
// Print the content of the screen
printScreen( ps );
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?