0
다음 코드에서 제목과 본문은 한 단어 뒤에 잘립니다. 나는 문자열이 여러 단어를 가질 수 있다고 생각 했는가? 누군가 이걸 정리할 수 있을까요? 감사합니다내 문자열이 한 단어로 제한되는 이유는 무엇입니까? (C++)
#include <fstream.h>
#include <iostream.h>
#include <string>
using namespace std;
string data, newtitle, body;
ofstream outfile;
int main()
{
cout << "enter title of note: ";
cin >> newtitle;
cout << "enter body of note: ";
cin >> body;
data = newtitle + ".dat";
outfile.open(data.c_str(), ios::out);
outfile << body << endl;
outfile.close();
system("pause");
}
'std :: string '은 여러 단어를 포함 할 수 있습니다. 'cin >> newtitle;'은 공백 문자를 찾으면 스캔을 멈 춥니 다. –
당신이 그것을 채우는 방식이 잘못되었다고 생각하지 않고 문자열을 비난하는 신비한 실수! –