积极答复者
如何返回一组字符串,并用指针指向这组字符串的首字母

问题
-
如何返回一组字符串,并用指针指向这组字符串的首字母
- 已编辑 Sheng Jiang 蒋晟Moderator 2010年11月7日 23:27 标题含糊
答案
-
以下代码仅供参考
#include <stdlib.h> #include <time.h> #include <string.h> #include<iostream> using namespace std; #define DATACOUNT 8 void Test(char* p, int nLen); int main() { char* pGet = new char[10]; Test(pGet, 10); cout<<"the first letter:"<<pGet[0]<<endl; cout<<pGet<<endl; delete pGet; system("pause"); return 1; } void Test(char* p, int nLen) { strcpy_s(p, nLen, "test"); }
- 已标记为答案 Daoping Liu - MSFTModerator 2010年11月12日 10:37
全部回复
-
以下代码仅供参考
#include <stdlib.h> #include <time.h> #include <string.h> #include<iostream> using namespace std; #define DATACOUNT 8 void Test(char* p, int nLen); int main() { char* pGet = new char[10]; Test(pGet, 10); cout<<"the first letter:"<<pGet[0]<<endl; cout<<pGet<<endl; delete pGet; system("pause"); return 1; } void Test(char* p, int nLen) { strcpy_s(p, nLen, "test"); }
- 已标记为答案 Daoping Liu - MSFTModerator 2010年11月12日 10:37