利用find()时出现了一些未知错误
我是想从CSV文件中提取Email Address
我的思路是首先找到@的位置,然后再向前找"和向后找"取得位置,再提取出来
#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;}