[問題] 如何讓後面的亂碼不出現?
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):s
#include<iostream>
#include<cstdlib>
using namespace std;
class CWin
{
public:
char id;
int width;
int height;
char title[50];
char *title1;
int area()
{
return width*height;
}
int set_title()
{
display();
}
int display()
{
cout<<"title :";
for(int i=0;i<=49;i++)
{
cout<<*(title1+i);
}
cout<<endl;
}
};
int main()
{
CWin win1;
win1.id='A';
win1.width=50;
win1.height=40;
cin.getline(win1.title,5);
win1.title1=win1.title;
cout<<win1.set_title();
cout<<"Window"<<win1.id<<":"<<endl;
cout<<"Area="<<win1.area()<<endl;
cout<<"sizeof(win1)="<<sizeof(win1)<<"bytes"<<endl;
system("pause");
return 0;
}
輸入:abcd
輸出結果:
title :abcd XXXX後面一堆亂碼
4469696WindowA: (4469696這一段也不知道從哪跑出來的)
Area=2000
sizeof(win1)=68bytes
請幫幫小弟一下,問題出在哪?
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.46.218
→
09/07 12:29, , 1F
09/07 12:29, 1F
→
09/07 12:31, , 2F
09/07 12:31, 2F
→
09/07 12:44, , 3F
09/07 12:44, 3F
→
09/07 13:06, , 4F
09/07 13:06, 4F
推
09/07 13:07, , 5F
09/07 13:07, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章