我必须处理来自的 [[nodiscard]] 警告std::remove
;
static_cast<void>(std::remove(stringVar.begin(), stringVar.end(), ' '));
我想要正确的方法来做到这一点。可以通过以下代码停止警告:
auto temp = std::remove(stringVar.begin(), stringVar.end(), ' ');
我不想使用std::remove
.
void main()
{
std::string stringVar { "Operation : In , Value : 3884 ," };
size_t from = 0, to = 0, pos = 0;
std::string delFrom{ ":" }, delTo{ "," };
static_cast<void>(std::remove(stringVar.begin(), stringVar.end(), ' '));
from = stringVar.find(delFrom, pos);
to = stringVar.find(delTo, pos);
std::cout<< stringVar.substr(from + 1, to - from - 1);
}
输出:
In
这是一个对 SO 上已经搜索过的问题不感兴趣的特定问题。
更新:数据一致且可读的格式。