cout << "Enter QUERY" << endl;
cin.ignore();
getline(cin, sql);
SQL문을 입력받는다고 가정하자.
SQL] SELECT * FROM TABLE1
만약, 저 위의 함수가 아닌,
cin >> sql을 쓰면 위의 SQL문장은 다음과 같이 입력된다.
SELECT*FROMTABLE1
따라서, 띄어쓰기를 포함해서 입력받고 싶으면,
getline 함수를 써야한다.
getline함수로 입력받기전에, cin.ignore() 함수를 불러 줘야 하는데,
그 이유는 stackoverflow에 정리되어있다. https://stackoverflow.com/questions/21686762/why-do-we-need-to-use-cin-ignore-before-getlinecin-string
Why do we need to use cin.ignore() before getline(cin, string)?
Why do we need to use cin.ignore() before taking input in a string? What is the backhand process? Why does it skip the input in a string (if we call getline function for more variables) if we don'...
stackoverflow.com
'프로그래밍 언어 > C++' 카테고리의 다른 글
C++ 동적할당(dynamic allocation) (0) | 2021.05.30 |
---|---|
C++ const argument (0) | 2020.09.17 |
C/C++의 call by value,call by reference, call by reference란 (0) | 2020.04.17 |