利用find()时出现了一些未知异常
利用find()时出现了一些未知错误
我是想从CSV文件中提取Email Address
我的思路是首先找到@的位置,然后再向前找"和向后找"取得位置,再提取出来
test.txt文本内容如下
cloverstd,"cloverstd@gmail.com",3512345
yangyi,"cloverstd@foxmail.com",3515555
YY,"kangfen@foxmail.com",3511111
"yanshaohui","yanshaohui@sina.com","","","","","","","",""
"waggshbang","wagghhbang@qq.com","","","","","","","",""
然后出现的是运行错误
不知道为什么会不能提取出Email Address来,后面还会多点东西
------解决方案--------------------
字符串的'\0'没有啊
我是想从CSV文件中提取Email Address
我的思路是首先找到@的位置,然后再向前找"和向后找"取得位置,再提取出来
- C/C++ code
#include<iostream> #include<fstream> #include<vector> using namespace std; int main() { vector<string> st; vector<string> st_save; ifstream inFile; inFile.open ("test.txt"); if (!inFile.is_open()) { cout<<" 打开失败了\n"; } st.clear(); st_save.clear(); string stemp; while (getline(inFile, stemp)) st.push_back(stemp); for (vector<string>::iterator it = st.begin(); it != st.end(); it++) { stemp = *it; size_t At_pace = stemp.find_first_of ('@'); //找到@的位置 if (! (At_pace == string::npos) ) { size_t first_quotation = stemp.find_last_of ('"',At_pace); //搜索@前一个引号的位置 size_t last_quotation = stemp.find_first_of ('"',At_pace); //搜索@前一个引号的位置 size_t st_lengtn = last_quotation - first_quotation - 1; //取得Email Address的长度 char st_email[st_lengtn]; for (size_t i = 0; i < st_lengtn; ++i) { st_email[i] = stemp[first_quotation+1+i]; } cout<<endl<<first_quotation<<","<<last_quotation<<","<<st_email; st_save.push_back(st_email); } } cout<<endl; cout<<endl; for (vector<string>::iterator it = st_save.begin(); it != st.end(); ++it) { cout<<*it<<endl; } cout<<"Done.\n"; inFile.close(); return 0; }
test.txt文本内容如下
cloverstd,"cloverstd@gmail.com",3512345
yangyi,"cloverstd@foxmail.com",3515555
YY,"kangfen@foxmail.com",3511111
"yanshaohui","yanshaohui@sina.com","","","","","","","",""
"waggshbang","wagghhbang@qq.com","","","","","","","",""
然后出现的是运行错误
不知道为什么会不能提取出Email Address来,后面还会多点东西
------解决方案--------------------
字符串的'\0'没有啊