【发布时间】:2013-08-31 09:00:41
【问题描述】:
以下代码从 char 数组中正确删除了标点符号:
#include <cctype>
#include <iostream>
int main()
{
char line[] = "ts='TOK_STORE_ID'; one,one, two;four$three two";
for (char* c = line; *c; c++)
{
if (std::ispunct(*c))
{
*c = ' ';
}
}
std::cout << line << std::endl;
}
如果line 是std::string 类型,这段代码会是什么样子?
【问题讨论】:
-
您可以使用
std::string数组访问运算符[]来操作字符串中的单个字符。
标签: c++ string parsing stdstring