0

这是我想要做的:

#include <iostream>

void out(box boxx);
struct box {
    char charr;
    float floatt;
};

int main()
{
    box boxx;
    boxx.charr = 'f';
    boxx.floatt = 2.5;
    out(boxx);
}

void out(box boxx)
{
    std::cout << boxx.charr << "\n" << boxx.floatt;
}

我想制作一个从结构中打印数据的函数。

4

1 回答 1

1

将函数声明移到结构之后。

 #include <iostream>

 
 struct box {
 char charr;
 float floatt;
 };
void out(box boxx);
int main()
{
  box boxx;
 boxx.charr = 'f';
 boxx.floatt = 2.5;
 out(boxx);
}

void out(box boxx)
{
 std::cout << boxx.charr << "\n" << boxx.floatt;
}
于 2020-07-06T12:58:19.203 回答