c·c++/c++ 프로그래밍

getline

바로이순간 2012. 8. 16. 21:17

#include <iostream>

#include <string>

using namespace std;

int main() {

    string words[10];

    string temp;

    int i, j,  n, x;


    cout<<"입력을 종료하려면 그낭 엔터를 누르세요 "<<endl;

    i=0;

    while(i<10) {

        cout<<i+1<<"번째 단어 : ";

        getline(cin, words[i]);

        if(words[i]=="") break;

        i=i+1;

    }

    n=i;

    for(i=0;i<n-1;++i) {

        x=i;

        for(j=i+1;j<n;++j) 

            if(words[x]>words[j]) x=j;

        temp=words[i];

        words[i]=words[x];

        words[x]=temp;

    }

    for(i=0;i<n;++i) cout<<words[i]<<" ";   


    return 0;

}