wString 截取字符串

来源:互联网 发布:找男妓的体验知乎 编辑:程序博客网 时间:2024/06/05 04:21

对于网上复制的某些有行号的代码,测试运行的时候 处理行号。

因为处理某些字符串我还是喜欢用C++

1    xxxxxxxxxxxxx            //我是中文注释啦啦啦

2    xxxxxxxxxx

...

101xxxxxxxxxx   //我是中文注释啦啦啦

102xxxxxxxxxx

一开始用C++ string 哦对哦 注释有中文乱码了,要用宽字符集,没怎么用过。谷歌这两天上不去不太好查


 用python 可能两三行就好了吧,re.sub(^[0-9]{1,3});

不过这怎么能行。。。

还是用了C++宽字符,一开始不会用。。。然后中文占两个字符,字符占一个,因为这里开头都是3个符号,行号和占位的空格组成,所以比较容易。


#include<iostream>#include<cstring>using namespace std;int main(){wstring wstr[300];int index = 0;while (getline(wcin,wstr[index])){  wstr[index]=wstr[index].substr(3);wcout << wstr[index];index++;}for (int i = 0; i < index; i++){wcout << wstr[i];cout << endl;}return 0;}



原创粉丝点击