C++中搜索字母和定位问题(高分悬赏)

来源:百度知道 编辑:UC知道 时间:2024/06/25 04:08:11
在一个字符串中 如何找到里面的大写字母并且定位在第几行第几列 还要把它更改成小写字母呢
没错 就是在C++读取文件的时候 要更改文件的内容

搞定,

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cctype>
using namespace std;

int main()
{
string file("xxx.txt");
ifstream i(file.c_str());
char c;
int row,col;
row = 1;
col = 0;
while(i) {
i.get(c);
if(c == '\n') {
++row;
col=0;
}
else ++col;
if(isupper(c))
cout << "row:" << row
<< " col:" << col
<< "char:" << c << endl;
}
i.clear();
i.seekg(ios::beg);
stringstream os;
os << i.rdbuf();
i.close();

string s(os.str());
for(string::size_type i = 0; i < s.size(); ++i)