c++问题呀~!有一个汉字数组。我想查询里面的固定汉字。如果查询到有固定的字符进行删除操作。比如:
123 116300 广东省深圳市 13804948474
134 116543 北京市东城区 13292928475
235 198672 香港特别行政区 13904948474
456 404986 中华人民共和国 13465867533
我已经把上面做成一个数组 a[]。 汉字那部分为数组a[2]. 要的效果是 把含有 “省” 或者“市”的字眼的一整行全删除。 要的效果应该是剩下最后两行。。 小弟初学c++。希望个哥哥们能帮个忙,写段实现的代码。最好把检查有没有含有“省”或者“市”的字符写成一个小方法。然后调用。小弟感激不尽啊!!!!!!!!!!!!!!!
[解决办法]
#include <iostream> // 数据流输入/输出#include <string> // 字符串类#include <algorithm> // STL 通用算法#include <fstream> //文件输入/输出#include <sstream> //文件输入/输出using namespace std;int main(){ string inStr = "123 116300 广东省深圳市 13804948474\n" "134 116543 北京市东城区 13292928475\n" "235 198672 香港特别行政区 13904948474\n" "456 404986 中华人民共和国 13465867533\n"; stringstream oss(inStr);// ifstream oss("输入文件.txt"); // 以上等价这行 string line; size_t pos; while (getline(oss, line)) { pos = line.find("市"); if (pos != string::npos) continue; pos = line.find("省"); if (pos != string::npos) continue; cout << line << endl; // 剩余输出 } return 0;}