Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
a をストリーミングしたいのstd::stringですが、最初の 2 文字または最後の 2 文字なしで実行できるようにしたいです。
std::string
例えば:
string foo{"bu blah blah blee le"}; cout << foo.substr(2) << endl << foo.substr(0, foo.size() - 2) << endl;
iomanipそのためのツールはありますか?それとも、先に進んで一時的なstrings を作成する必要がありますか?
iomanip
string
使用できますcout.write:
cout.write
cout.write(foo.c_str() + 2, foo.size() - 4);
これもストリームを返すので、次のことができます。
cout << "First two: "; cout.write(foo.c_str(), 2) << "\nAll but first two: "; cout.write(foo.c_str() + 2, foo.size() - 2) << '\n';