C++ の C スタイルの文字列が という形式であるとします[4 letters] [number] [number] ...
。たとえば、文字列は次のようになります。
abcd 1234 -6242 1212
文字列には空白が多すぎることが予想されることに注意してください (上記を参照)。
これら 3 つの数値を抽出して配列に格納するにはどうすればよいでしょうか?
stringstreams の仕事です。ライブでご覧ください: http://ideone.com/e8GjMg
#include <sstream>
#include <iostream>
int main()
{
std::istringstream iss(" abcd 1234 -6242 1212");
std::string s;
int a, b, c;
iss >> s >> a >> b >> c;
std::cout << s << " " << a << " " << b << " " << c << std::endl;
}
版画
abcd 1234 -6242 1212