큰 메시지를 cout으로 출력하고 싶습니다.여러 줄의 Cout C++
예 :
cout<<"Camera could not be opened in the requested access mode, because another
application (possibly on another host) is using the camera."<<endl;
하지만 오류가 발생합니다.
어떤 도움이 필요합니까? 이런
큰 메시지를 cout으로 출력하고 싶습니다.여러 줄의 Cout C++
예 :
cout<<"Camera could not be opened in the requested access mode, because another
application (possibly on another host) is using the camera."<<endl;
하지만 오류가 발생합니다.
어떤 도움이 필요합니까? 이런
예시 :
cout<<"Camera could not be opened in the requested access mode, because another "
"application (possibly on another host) is using the camera."<<endl;
또는 C 및 C++에서
cout<<"Camera could not be opened in the requested access mode, because another\n"
"application (possibly on another host) is using the camera."<<endl;
은 서로 옆에 두 문자열이 컴파일러에 의해 연접된다.
원본 버전도 작동해야합니다 (어쩌면 초과 공백이 있음) –
꽤 긴 오류 메시지입니다. 어딘가에서 개행을 원할 수도 있습니다. – Emmet
@MattMcNabb : 정말요? 문자열의 중간에 개행 문자가있을 때 g ++ 및 clang ++ 객체 모두. 어떤 컴파일러를 사용하고 있는지 확실하지 않습니다 ... –
여러 줄에 걸쳐 일반 문자열 리터럴을 직접 분할 할 수 없습니다. 연결 문자를 사용하여 여러 줄로 나눌 수 있다고 생각합니다. 그러나이 또한 개행을 포함하지 않습니다. 이것을 얻으려면 \n
을 사용해야합니다. 그래도 원시 문자열 리터럴을 사용할 수 있다고 생각합니다.
char const* strcont = "foo\
bar";
char const* strcat = "foo"
"bar";
char const* strraw = R"(foo
bar)";
첫 번째 두 문자열은 동일합니다. 인접한 문자열이 연결됩니다. 세 번째 것은 개행 문자를 포함한다.
.. 무엇이 오류입니까? – Arun
오류 메시지 인 경우 틀림없이'cout'보다는'cerr'으로 보내야합니다. – Emmet