-4
我想处理一个随机大小的字符串,并修改所有包围某些模式的数字。例如,如何搜索和修改C++中某个字符串所包围的数字?
string oldstring =“res 0.25 cap 0.12 tra 1 res 0.3 cap”; string newstring =“res 0.50 cap 0.12 tra 1 res 0.6 cap”;
所以“res”和“cap”之间的所有数字都乘以2. 我只知道如何搜索特定的子字符串(使用stringstream,token,while循环和getline),但我不知道如何搜索“res ... cap”这样的模式并修改它们之间的数字。
任何人都可以给我一些指导?
也许'的std :: regex'可以派上用场。 – user0042
您需要[预约您的橡皮鸭](https://en.wikipedia.org/wiki/Rubber_duck_debugging)进行咨询。我相信你可以从你的橡皮鸭中得到一些很好的建议。 –
你也应该仔细看看:http://www.cplusplus.com/reference/string/string/,看看你有什么可用的。 – zzxyz