Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用c+解析随机字符串+;_C++_String - Fatal编程技术网

C++ 使用c+解析随机字符串+;

C++ 使用c+解析随机字符串+;,c++,string,C++,String,我有一些字符串没有遵循任何特定的模式。。e、 g t\u pl\u温度+= 温度= t\u温度 temperatureArray[] “温度”。。开头有空格 #定义温度 temperatureTemp int温度 当前温度 温度高温度低返回(温度) 我只想改变温度,到目前为止我已经使用了 std::string str = temperature; size_t start_pos = str.find (str); replace (start_pos, str.length(), "chan

我有一些字符串没有遵循任何特定的模式。。e、 g

t\u pl\u温度+=
温度=
t\u温度
temperatureArray[]

“温度”
。。开头有空格

#定义温度
temperatureTemp
int温度
当前温度

温度高
温度低
返回(温度)

我只想改变温度,到目前为止我已经使用了

std::string str = temperature;
size_t start_pos = str.find (str);
replace (start_pos, str.length(), "changed");
在这样做的同时,它改变了每一个温度与其他文字在同一行发生。我使用str.at(start_pos)和str.at(start_pos+str.length())的组合以及一些使用

using namespace boost;
std::ostringstream s;
char_separator<char> sep("=");  
tokenizer<char_separator<char>> tokens(str, sep);
for (const auto& t : tokens) {
    s << t;
}

return s.str();
使用名称空间boost;
std::ostringstream s;
字符分隔符sep(“=”);
标记器标记(str、sep);
for(const auto&t:tokens){

这听起来像是一项工作,我不明白你为什么要使用boost标记器…只需要像这样的
(start|pos==0||!isidn(bigstr.at(start|pos-1))&(start|pos+str.length()==bigstr.length()| isidn(bigstr.at(start|pos+str.length()))
,其中,
isidn
检查标识符的有效字符,
bigstr
是您的全部文本,
str
是温度-您不能同时称它们为
str
。正则表达式是另一个很好的选择…我认为检查单词边界的是
\b
。有什么特别的原因需要解释吗哦,这是用C++而不是shell脚本?@ Tony D。是的,我已经尝试过这些组合,它们工作,但不是每次。例如,它改变温度,但是如果下一个字符串要改变的话是TyTo温度等等。我知道正则表达式是一个答案,但我有点回避它,但是好像我必须进入这艘船!如果下一个字符串是
t\u temperature
上面的测试将不匹配,因为
!isidn(bigstr.at(start\u pos-1))
将在标识符中将下划线识别为合法字符…这不是您想要的吗?