R
raan
Whats wrong with the code ? delete[] tp; is throwing DAMAGE: After
normal block(#56) at 0x00321480
Environment, VS2003, XP
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
string PutS(std::string& type)
{
char *tp;
tp = new char[type.length()+1];
type.resize(type.length() + 1);
memcpy(tp, type.c_str(), strlen(type.c_str()));
*(tp + type.length()-1) = 's';
*(tp + type.length()) = '\0';
string ntype(tp);
cout << ntype.c_str();
delete[] tp;
return ntype;
}
int main()
{
std::string type = "CAMERA";
PutS(type);
getchar();
}
normal block(#56) at 0x00321480
Environment, VS2003, XP
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
string PutS(std::string& type)
{
char *tp;
tp = new char[type.length()+1];
type.resize(type.length() + 1);
memcpy(tp, type.c_str(), strlen(type.c_str()));
*(tp + type.length()-1) = 's';
*(tp + type.length()) = '\0';
string ntype(tp);
cout << ntype.c_str();
delete[] tp;
return ntype;
}
int main()
{
std::string type = "CAMERA";
PutS(type);
getchar();
}