错误:'' 未在此范围内声明

拉斐尔席尔瓦

我试图做一个简单的程序来了解更多关于参考段落、指针以及如何在 C++ 中的结构上使用这 2 的知识,但我遇到了一些问题。

我在下面的代码中遇到错误“错误:'totalStudent' 未在此范围内声明”,我的问题是,我应该如何声明“totalStudent”。

#include <iostream>
using namespace std;

struct test{
    char name[30];
    int age;
};

void addStudent(struct test *ptrTest,int *totalStudent){
    for(int i=0;i<2;i++){
        cout<<"\nInsert the name: ";
        cin.sync();
        cin.getline(ptrTest->name,sizeof(ptrTest->name));
        cout<<"\nInsert the age: ";
        cin.sync();
        cin>>ptrTest->age;
        *totalStudent+=1;
    }

}

void showStudent(struct test *ptrTest,int totalStudent){
    for(int i=0;i<totalStudent;i++){
    cout<<"\nName: "<<ptrTest->name;
    cout<<"\nAge: "<<ptrTest->age;
    }
};

int main()
{
    struct test t;
    addStudent(&t,&totalStudent);
    showStudent(&t,totalStudent);
    return 0;
}

我不能很好地使用带有结构的指针和参考段落。我只能在不使用结构时使用它们。

亚历克斯·洛普。

您忘记在以下范围内声明此变量main

int main()
{
    struct test t;
    // LIKE THIS
    int totalStudent;

    addStudent(&t,&totalStudent);
    showStudent(&t,totalStudent);
    return 0;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:未在此范围内声明“ _hypot”

错误:未在此范围内声明“ qmlRegisterType”

错误:未在此范围内声明“ strdup”

C ++错误:未在此范围内声明睡眠

错误:未在此范围内声明“ TCP_NODELAY”

未在此范围内声明“ AddCustomer”。错误在哪里?

错误:未在此范围内声明“对象”(C ++)

未在此范围内声明CvSVM错误

错误:未在此范围内声明“ random_device”

错误:未在此范围内声明“对象”

错误:“numeric_limits”未在此范围内声明

非平凡的“未在此范围内声明”错误

错误:未在此范围内声明“ enumElement”

Cygwin错误:系统未在此范围内声明?

错误:未在此范围内使用C ++声明

错误:未在此范围内声明“设置”

未在此范围内声明变量gcc错误

未在此范围内声明C ++构建错误

错误:未在此范围内声明“ GlobalRNG”

错误:变量未在此范围内声明

错误:未在此范围内声明 FILE

在 Arduino 中声明函数时出现“未在此范围内声明函数”错误

错误:“_cal_order”未在此范围内声明 - 范围问题

未在范围内声明。多重错误

Android JNI C ++中的“未在此范围内声明”错误

c ++:混淆为什么编译器给出未在此范围内声明的错误

C ++错误:未在此范围内声明“ _mm_sin_ps”

在arduino中未在此范围内声明“ QTR_NO_EMITTER_PIN”中的错误?

C++ switch 语句错误(变量未在此范围内声明)