Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

replace line in a file C++ -


i'm trying find way replace line, containing string, in file new line.

if string not present in file, append file.

can give sample code?

edit : there anyway if line need replace @ end of file?

although recognize not smartest way it, following code reads demo.txt line line , searches word cactus replace oranges while writing output secondary file named result.txt.

don't worry, saved work you. read comment:

#include <iostream> #include <fstream> #include <string> #include <algorithm>  using namespace std;   int main() {   string search_string = "cactus";   string replace_string = "oranges";   string inbuf;   fstream input_file("demo.txt", ios::in);   ofstream output_file("result.txt");    while (!input_file.eof())   {       getline(input_file, inbuf);        int spot = inbuf.find(search_string);       if(spot >= 0)       {          string tmpstring = inbuf.substr(0,spot);          tmpstring += replace_string;          tmpstring += inbuf.substr(spot+search_string.length(), inbuf.length());          inbuf = tmpstring;       }        output_file << inbuf << endl;   }    //todo: delete demo.txt , rename result.txt demo.txt   // achieve replace effect. } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -