上次寫的截取方法有些復雜了,現在有個簡單的,代碼如下:
#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()); }
運行結果如下: