上次写的截取方法有些复杂了,现在有个简单的,代码如下:
#include <iostream> #include <string> #include<cstdio> #include<vector> #include<typeinfo> using namespace std; int main() { string contentStr ="2017年04月01日10时48分19秒 基准测试_小白兔_feeder1 test_sg_kg 大灰狼(后台补)"; int blankPos = contentStr.find_first_of(' '); string timfStr = contentStr.substr(0,blankPos); string contentTmp = contentStr.substr(blankPos); blankPos = contentTmp.find_first_not_of(' '); contentTmp = contentTmp.erase(0,blankPos); printf("----------timfStr:%s\n",timfStr.c_str()); printf("----------contentTmp:%s\n",contentTmp.c_str()); }
运行结果如下: