指针的奇怪问题:
MyPointer.h
-------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
class MyPointer
{
public:
string ConvertAString(string s);
};
MyPointer.cpp
------------------------------------
#include "MyPointer.h"
//将一个字符串逆转过来
string MyPointer::ConvertAString(string s)
{
char *pStr=tempnam(s.c_str(),NULL);
char* temp=new char;
int count=s.size();
for(int i=0;i<s.size()/2;i++)
{
*(pStr+i)=*(pStr+count+i);
}
string ret(pStr);
return ret;
}
main.cpp
--------------------------------------------
#include <iostream>
#include <stdlib.h>
#include "MyPointer.h"
using namespace std;
int main(int argc, char *argv[])
{
MyPointer pointer;
string str=pointer.ConvertAString("thisisastring");
cout<<str;
system("PAUSE");
return 0;
}
我想将实现一个字符串的翻转操作,可是为什么输出结果是:
DMINI~UME~1\ADMINI~1\LOCALS~1\Temp\2