C++汉英混合的字符串截取
目前来看s.find(str)返回值都是-1,用s.substr(idx)从八位以后截取就会报错
#include<iostream>
#include<string>
#include<regex>
#include<cstdlib>
#include< locale>
#include <codecvt>
using namespace std;
void cut(wstring a) {
wstring next;
wstring h = L"荣耀";
int head,end;
wregex regexstr(L"^0.*"); //输入多行字符串处理,直到输入一个以0开头的字符串结束。
wsmatch resault;
if (regex_match(a, resault, regexstr)) cout<<"back"<<endl;
else {
getline(wcin, next);
cut(next); //用递归实现处理完一并输出
}
head = a.find(h); //返回值恒为-1
if(head>0)
wcout<<a.substr(head)<<endl; //只有把head改成具体值(<=8)可以截取
}
int main()
{
wstring a;
getline(wcin,a);
cut(a);
}
刚学c++,一开始string处理不了汉字改为wstring,想先获取指定字符串位置再截取,但是s.find和s.substr现在都有问题,求拯救!!