本帖最后由 bin554385863 于 2019-9-14 19:44 编辑 #include <stdio.h>
struct num
{
char x;
int y;
};
int main(int argc, char const *argv[])
{
int n = 5;
struct num arr[n];
for (size_t i = 0; i < n; i++)
{
arr[i].x = 'a' + i;
arr[i].y = i;
}
for (size_t i = 0; i < n; i++)
{
printf("arr[%d](%c , %d)\n", i, arr[i].x, arr[i].y);
}
return 0;
}
----------------------------------------------------------------------------
Microsoft Windows [版本 10.0.16299.1087]
(c) 2017 Microsoft Corporation。保留所有权利。
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.25.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-bjxofrn1.njt --stdout=Microsoft-MIEngine-Out-cgeou2vr.qnc --stderr=Microsoft-MIEngine-Error-sgfv4nd4.pd4 --pid=Microsoft-MIEngine-Pid-oh4l2mo1.nx0 "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
arr[0](a , 0)
arr[1](b , 1)
arr[2](c , 2)
arr[3](d , 3)
arr[4](e , 4)
E:\Users\86184\Documents\Code>
----------------------------------------------------------------------
或者
C++#include <iostream>
struct num
{
char x;
int y;
};
int main(int argc, char const *argv[])
{
int n = 5;
struct num arr[n];
for (size_t i = 0; i < n; i++)
{
std::cin>>arr[i].x>>arr[i].y;
}
for (size_t i = 0; i < n; i++)
{
printf("arr[%d](%c , %d)\n", i, arr[i].x, arr[i].y);
}
return 0;
}
--------------------------------------------------------------------------------------------
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.25.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-vzsyujsh.jnr --stdout=Microsoft-MIEngine-Out-kb0qq0kz.jbs --stderr=Microsoft-MIEngine-Error-flz0k4io.1jy --pid=Microsoft-MIEngine-Pid-tgdlmxgw.1yi "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
a 2
b 6
v 9
r 9
l 4
arr[0](a , 2)
arr[1](b , 6)
arr[2](v , 9)
arr[3](r , 9)
arr[4](l , 4)
E:\Users\86184\Documents\Code> |