강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

호두님의 프로필 이미지
호두

작성한 질문수

홍정모의 따라하며 배우는 C++

4.6 문자열 std string 소개

[10:30]<자답> cin에 빈칸이 있는 문자열 넣을 때 문제

해결된 질문

작성

·

215

1

질문을 작성하면서 정리가 된다는 걸 경험했습니다.

<code>

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "Your name : " << endl;
    string name;
    cin >> name;
    cout << endl;
    // cin.ignore();

    cout << "Your age : " << endl;
    string age;
    cin >> age;
    cout << endl;

    cout << "address : " << endl;
    string addr;
    cin >> addr;
    cout << endl;

    cout << name << "##" << age << "##" << addr << endl;

    return 0;
}

<output>

PS C:\coding\tbc_review\TBCPP\Chapter4> .\a.exe

Your name :

hong gil dong

Your age :

address :

hong##gil##dong

요렇게 빈칸을 기준으로 문자열을 받는거네요.

감사합니다.

답변 1

1

홍정모님의 프로필 이미지
홍정모
지식공유자

맞습니다. 저도 질문해놓고 스스로 답을 얻은 경우가 많습니다.

호두님의 프로필 이미지
호두

작성한 질문수

질문하기