반응형


책을 보다 보니


**************************

*   Hello,  이름                 *

**************************

를 보니 구현해보라는 장이 나왔고  이쯤이야 하면서 

string hello = "Hello, ";

    string input;
    cout << "Please enter your first name : ";
    cin >> input;
    for(int i = 0; i < input.size()+hello.size() + 4; i++){
        cout << "*";
    }
    cout << endl;
    cout << "* "<<hello << input <<" *"<<endl;
    for(int i = 0; i < input.size()+hello.size() + 4; i++){
        cout << "*";
    }

cout << endl;

로 구현하였다 .


책에 내용에서 의 코딩방법은

cout << "Please enter your first name : ";
string naem; cin >> name;

const string greetin = " Hello, " + name + "!";

const string spaces(greeting.size() ' ');

const string second = "* " + spaces + " *";

const string first(second.size(),'*');


const string first(second.size(),'*');

위와같은 방법으로하면 for문대신 간단히 처리할 수 있었다.



....좀더 분발하자...






반응형

+ Recent posts