程序是可以执行的,但在运行时,它跳过限定值并跳到最高值。

问题描述 投票:0回答:1
#include<iostream>
using namespace std;
struct teacher 
{
    char name[20];
    int id;
    char grade[20];
    char qual[20];
    char heighest[20];  
};


int main()
{
    teacher t1,*ptr_t1;
    ptr_t1=&t1;
    cout<<"please Enter your Name \n";
    gets(ptr_t1->name);
    cout<<"please Enter your grade\n";
    gets(ptr_t1->grade);
    cout<<"please Enter your ID \n";
    cin>>ptr_t1->id;
    cout<<"please Enter your Qualification \n";
    gets(ptr_t1->qual);
    cout<<"please Enter your heighest \n";
    gets(ptr_t1->heighest); 
    system("pause");
    return 0;
}

这是我的代码get(ptr_t1->qual)不接受任何值,我的程序跳转到get(ptr_t1->heighest),我在其中遇到了问题。

c++ runtime-error executable trouble-tickets
1个回答
0
投票

你不应该把 cingets. 相反,你可以随时使用 cin:

#include<iostream>
using namespace std;

struct teacher 
{
    char name[20];
    int id;
    char grade[20];
    char qual[20];
    char heighest[20];  
};


int main()
{
    teacher t1,*ptr_t1;
    ptr_t1=&t1;

    cout << "please Enter your Name \n";
    cin >> ptr_t1->name;
    cout << "please Enter your grade\n";
    cin >> ptr_t1->grade;
    cout << "please Enter your ID \n";
    cin >> ptr_t1->id;
    cout << "please Enter your Qualification \n";
    cin >> ptr_t1->qual;
    cout << "please Enter your heighest \n";
    cin >> ptr_t1->heighest; 

    system("pause");
    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.