最初の括弧「(」と最後の括弧「(」の間のすべての文字を削除するのに問題があります。これを機能させるために使用するテストプログラムを次に示しますが、成功しません...
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "( 1221 ( 0 0 0 ) (1224.478541112155452 (1.32544e-7 0 0 ) ) )";
int count = 0;
for (std::string::size_type i = 0; i < str.size(); ++i)
{
if (str[i] == '(')
{
count += 1;
}
cout << "str[i]: " << str[i] << endl;
if (count <= 4)
{
str.erase(0, 1);
//str.replace(0, 1, "");
}
cout << "String: " << str << endl;
if (count == 4)
{
break;
}
cout << "Counter: " << count << endl;
}
cout << "Final string: " << str << endl;
system("PAUSE");
return 0;
}
上記の例では、私の目標は (少なくとも) 文字列を取得することです。
"1.32544e-7 0 0 ) ) )"
元の文字列から抽出された
"( 1221 ( 0 0 0 ) (1224.478541112155452 (1.32544e-7 0 0 ) ) )"
より正確には、値を抽出したい
"1.32544e-7"
計算で使用するために double に変換します。
削除に成功しました
" 0 0 ) ) )"
それは一種の定数値だからです。
ありがとうございました!