[問題] *_*請問一個結構陣列的問題..
以下程式執行過程沒有問題,可是執行結束後,會跳出一個警告訊息..
Run-Time Check Failure #2 -Stack around the variable 'data' was corrupted.
我用的是Visual C++ 2008 Express的版本..
謝謝!!
============================================================================
#include <iostream> //載入的標頭檔
using namespace std; //定義使用std命名空間
struct student { //結構student的定義宣告
char name[20],age[20],grade[20];
};
int main(void)
{
int i;
//char data[3];
student data[3];
for(i=1;i<4;i++)
{
//結構變數的宣告,並設定初值
cout << "請輸入第 " << i << " 位學生資料: " << endl;
cout << "請輸入姓名: ";
cin >> data[i].name;
cout << "請輸入年齡: ";
cin >> data[i].age;
cout << "請輸入成績: ";
cin >> data[i].grade;
cout << endl;
}
cout << "=======================================================" << endl;
//顯示結構變數之各成員值
for(i=1;i<4;i++)
{
cout << "第 " << i << " 位學生資料: " << endl;
cout << "姓名= " << data[i].name << endl;
cout << "年齡= " << data[i].age << endl;
cout << "成績= " << data[i].grade << endl;
cout << endl;
}
system("PAUSE"); //暫停程式執行
return 0; //程式正常結束,傳回0
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.133.74.124
推
12/30 11:47, , 1F
12/30 11:47, 1F
→
12/30 11:47, , 2F
12/30 11:47, 2F
推
12/30 12:35, , 3F
12/30 12:35, 3F
→
12/30 15:02, , 4F
12/30 15:02, 4F
推
12/30 16:36, , 5F
12/30 16:36, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章