saving the changes in file
<p><strong>Ojective:</strong> To open config file, look for a particular line which has tag and change its value </p>

<p><strong>Example:</strong>  </p>

<pre><code>    config .txt    
    bla bla    
    bla bla   
    SYSTEM_A_EXTERNAL_IP=192.168.0.57  // need to change ip address    
    bla bla   
    bla bla 
</code></pre>

<p><strong>What I have done so far:</strong>  My code  open the file and look for the particular line which has tag  and change its value . </p>

<p><strong>Problem:</strong> I failed to see those changes in the actual file. I am  aware that ofstream will write into line but if I  do ofstream instead of  ifstream  getline function gets an error.  </p>

<p><strong>Code1:</strong></p>

<pre><code>bool SetIpAddr(string &amp; iAddr)    
{     
    bool check= false;    

    // Open  file    
    ifstream  iFile(IpConfigFile.c_str(), ios_base::out|ios::app | ios::binary);
    if(iFile.is_open())    
    {    
        check= true;    
    }          

    // Read content of ipconf file searching for the value of Head Id Name
    if(true == check)
    {
        string TargetName = SystemAIdValue + ExternalIpNamePostfix+ ValueAssignmentCharacter;
        string outbuf;
        while( !iFile.eof() )
        {
            getline(iFile, outbuf);    

            // find the matching string     
            if( 0 == outbuf.compare(0,TargetName.size(),TargetName) )
            {
            outbuf.erase(outbuf.begin()+TargetName.size(), outbuf.end());    
            outbuf.insert(0+TargetName.size(), iAddr);
                std::cout&lt;&lt; " after insertion  " &lt;&lt; outbuf &lt;&lt; std::endl;
                break;
            }
        }
    }
    // Close  (input) file
    if( iFile.is_open() )
    {
        iFile.close();
    }
    return check; 
}
</code></pre>

<p><strong>Code2:</strong> Also doesnt work.</p>

<pre><code> bool SetIpAddr(string &amp; aIpAddr)
 {
     bool lResult = false;    
     std::fstream  ifile("platform_ip_config");      
     string lTargetIp = HeadAIdValue + ExternalIpNamePostfix+ ValueAssignmentCharacter;
     std::deque&lt;std::string&gt;lines;
     std::string inbuf;
     while( std::getline(ifile, inbuf));
     {
         std::cout&lt;&lt;" we are in while"&lt;&lt;std::endl;
         std::cout&lt;&lt;" getline =="&lt;&lt; inbuf&lt;&lt; std::endl;
         std::cout&lt;&lt;" ip =="&lt;&lt;lTargetIp&lt;&lt; std::endl;
         if( 0 == inbuf.compare(0,lTargetIp.size(),lTargetIp) )
         {
             std::cout&lt;&lt;" we are in matching"&lt;&lt;std::endl;            
             std::cout&lt;&lt; inbuf &lt;&lt; std::endl;
         inbuf.erase(inbuf.begin()+lTargetIp.size(), inbuf.end());
             std::cout&lt;&lt;" after erase " &lt;&lt; inbuf &lt;&lt; std::endl;
         inbuf.insert(0+lTargetIp.size(), aIpAddr);
             std::cout&lt;&lt; " after insertinon  " &lt;&lt; inbuf &lt;&lt; std::endl;        
         }
         lines.push_back(inbuf);
     } 
     ifile.seekg (0, ios::beg );
     std::copy(lines.begin(), lines.end(), 
     std::ostream_iterator&lt;std::string&gt;(ifile, "\n"));
  }
  lines.push_back(inbuf);
}
ifile.seekg (0, ios::beg );
std::copy(lines.begin(), lines.end(), 
std::ostream_iterator&lt;std::string&gt;(ifile, "\n"));
}
</code></pre>
