求助:C++文件操作: 换行 定位修改
list.txtTom 18 50 1.76
Bob 18 52 1.74
Kyle 18 55 1.79
程序代码:
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; int fileToVector(string fileName, vector<string> & svec) { ifstream inFile(fileName.c_str()); if (!inFile) return 1; string s; while (getline(inFile, s)) svec.push_back(s); inFile.close(); if(inFile.eof()) return 4; if(inFile.bad()) return 2; if(inFile.fail()) return 3; } int main() { vector<string> svec; string fileName("E:\\list.txt"), s; switch (fileToVector(fileName, svec)) { case 1: cout << "error: can not open file: " << fileName << endl; case 2: cout << "error: system failure " << endl; case 3: cout << "error: read failure " << endl; return 0; return -1; } cout << "Vector:" << endl; for(vector<string>::iterator iter = svec.begin(); iter != svec.end(); ++iter) cout << *iter << endl; return 0; }
运行环境:VC++6.0
请问:
如果要定位到Bob的体重:52,并修改它,要怎么实现
[ 本帖最后由 小颭 于 2011-7-17 09:39 编辑 ]