程序在delete那句中斷
源代碼:
#include< iostream >
#include< vector >
using std::vector;
#include< string >
using namespace std;
char* tran(string str)
{
char* t = new char[strlen(str.c_str()) + 1];
char* p = t;
strcpy_s(p,strlen(str.c_str())+1,str.c_str());
while (*p != 0)
{
if (*p >= 'a'&&*p <= 'z')
* (p++) -= 32;
else
++p;
}
p[strlen(str.c_str())] = 0;
return t;
}
void main()
{
vector< string > v;
string s;
char * t;
while (cin >> s&&*(s.c_str()) != '#')
v.push_back(s);
vector< string >::iterator iter = v.begin();
t = tran(*iter);
int len = strlen(t);
delete[] t;////////出錯////////////////
system("pause");
}
為何你會把 new出來的東西賦給一個char.....