该程序在VS2012中运行通过,但却等不到任何结果,在qt5.1中运行得到正确结果

说明:在qt运行时将strcpy_s改为了strcpy程序来源于c++primeplus第六版4.20//ptrstr.cpp--usingpointerstostrin... 说明:在qt运行时将strcpy_s改为了strcpy
程序来源于c++ prime plus 第六版4.20

// ptrstr.cpp -- using pointers to strings
#include <iostream>
#include <cstring> // declare strlen(), strcpy()
int main()
{
using namespace std;
char animal[20] = "bear"; // animal holds bear
const char * bird = "wren"; // bird holds address of string
char * ps; // uninitialized

cout << animal << " and "; // display bear
cout << bird << "\n"; // display wren

cout << "Enter a kind of animal: ";
cin >> animal; // ok if input < 20 chars

ps = animal; // set ps to point to string
cout << ps << "s!\n"; // ok, same as using animal
cout << "Before using strcpy():\n";
cout << animal << " at " << (int *) animal << endl;
cout << ps << " at " << (int *) ps << endl;

ps = new char[strlen(animal) + 1]; // get new storage
strcpy_s(ps,strlen(animal)+1, animal); // copy string to new storage
cout << "After using strcpy():\n";
cout << animal << " at " << (int *) animal << endl;
cout << ps << " at " << (int *) ps << endl;
delete [] ps;
return 0;
}
展开
 我来答
书儒生
2013-09-07 · 超过16用户采纳过TA的回答
知道答主
回答量:48
采纳率:0%
帮助的人:36.1万
展开全部
2012没问题;测试完毕;
追问
结果呢,上个图
追答

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式