2014-12-06 2 views
0

std::string을 스트리밍하고 싶지만 처음 두 자 또는 마지막 두 자 없이는이 작업을 수행 할 수 있기를 원합니다. 예를 들어스트림 출력 문자열 부분

:

string foo{"bu blah blah blee le"}; 

cout << foo.substr(2) << endl << foo.substr(0, foo.size() - 2) << endl; 

는 대한 iomanip 도구가 있습니까? 아니면 그냥 임시로 string을 만드시겠습니까? 또한 스트림을 반환

cout.write(foo.c_str() + 2, foo.size() - 4); 

을, 그래서 당신은 할 수 있습니다 :

답변

1

당신은 cout.write를 사용할 수

cout << "First two: "; 
cout.write(foo.c_str(), 2) << "\nAll but first two: "; 
cout.write(foo.c_str() + 2, foo.size() - 2) << '\n'; 
+1

그것은 같은 스트리밍이 아니다. – interjay

+0

@interjay 수정되었습니다. – Barry