#include <memory>
int main(void)
{
std::auto_ptr<int> p(new int(1));
// ...
if (/* some condition */)
{
p.reset(new int(1));
}
// ...
return 0;
}
#include <memory>
int main(void)
{
int* p = new int(1);
// ...
if (/* some condition */)
{
delete p;
p = new int (1);
}
// ...
delete p;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
string replace_str(const string& s, const string& from, const string& to)
{
string str;
int i=0,j=0;
while ( ( j = s.find(from,i) ) != -1 )
{
// cerr <<i <<','<<j <<endl;
str += s.substr(i,j) + to;
i = j + from.length();
}
str += s.substr(i);
return str;
}
int main(void)
{
c();
string aaa ="abcdefgcdefga";
cout << aaa << endl;
aaa = replace_str(aaa,"cde","@@@@");
cout << aaa << endl;
}