分类: C/C++
2008-05-07 22:03:35
cur.addBoard(new Board("CN","3078","四川")) cur.addBoard(new Board("CN","3256","天津")) cur.addBoard(new Board("CN","3290","西藏")) cur.addBoard(new Board("CN","3371","新疆")) cur.addBoard(new Board("CN","3478","浙江")) cur.addBoard(new Board("CN","3559","云南")) cur.addBoard(new Board("CN","1908","湖北")) cur.addBoard(new Board("CN","2258","江西")) cur.addBoard(new Board("CN","3262","重庆")) cur.addBoard(new Board("CN","2536","宁夏")) cur.addBoard(new Board("CN","2561","青海")) cur.addBoard(new Board("CN","2610","上海")) cur.addBoard(new Board("CN","2614","广东")) cur.addBoard(new Board("CN","2728","山西")) cur.addBoard(new Board("CN","2847","山东")) cur.addBoard(new Board("CN","1002","安徽")) cur.addBoard(new Board("CN","1098","北京")) cur.addBoard(new Board("CN","1103","福建")) cur.addBoard(new Board("CN","1181","甘肃")) cur.addBoard(new Board("CN","1277","广西")) cur.addBoard(new Board("CN","1382","贵州")) cur.addBoard(new Board("CN","1474","海南")) cur.addBoard(new Board("CN","1511","河北")) cur.addBoard(new Board("CN","1670","河南")) cur.addBoard(new Board("CN","1816","黑龙江")) cur.addBoard(new Board("CN","2002","湖南")) cur.addBoard(new Board("CN","2118","吉林")) cur.addBoard(new Board("CN","2177","江苏")) cur.addBoard(new Board("CN","2361","辽宁")) cur.addBoard(new Board("CN","2434","内蒙古"))
文件内容一行行读入CString中然后一个个查找
CString s;
size_t lpos = s.ReverseFind( ',' ); //0
size_t rpos = s.ReverseFind('\"' ); //5
s.Mid(lpos+1,rpos-lpos-2);
举个例子
- C/C++ code
int main(int argc, char* argv[]) { CString src = ",\"内蒙古\"))"; size_t lpos = src.ReverseFind( ',' ); size_t rpos = src.ReverseFind('\"' ); CString des = src.Mid(lpos+2,rpos-lpos-2); ASSERT(0 == des.Compare("内蒙古")); cout << "OK\n"; return 0; }
输出
OK
Press any key to continue
这样就找出来了