C++ 为什么赢了';程序运行时是否执行第二个循环?

C++ 为什么赢了';程序运行时是否执行第二个循环?,c++,for-loop,C++,For Loop,第一个循环运行完全正常,但第二个循环不显示数据。在第一个循环中输入数据后,程序结束。我是不是显示错了?顺序不对吗 #include <iostream> #include <string> using namespace std; struct Empinfo { string name; int pay; double hours; double gross_pay; }; int main() { int count; int index; const int a

第一个循环运行完全正常,但第二个循环不显示数据。在第一个循环中输入数据后,程序结束。我是不是显示错了?顺序不对吗

#include <iostream>
#include <string>

using namespace std;

struct Empinfo
{
string name;
int pay;
double hours;
double gross_pay;
};
int main()
{
int count;
int index;
const int arraysize = 3;
Empinfo employee[arraysize]; 
for (count = 0; count < arraysize; count++)
{
    cout << "Enter name of employee" << " " << (count + 1) << ":";
    cin >> employee[count].name;
    cout << "Enter the hourly pay for " << employee[count].name << ": ";
    cin >> employee[count].pay;
    cout << "Enter how many hours " << employee[count].name << "worked: ";
    cin >> employee[count].hours;
    cout << endl;

}
for (index = 0; index << arraysize; index++)
{
    cout << employee[index].name;
    cout << employee[index].pay;
    cout << employee[index].hours;
    cout << employee[index].gross_pay;

}
system("pause");
return 0;
}
#包括
#包括
使用名称空间std;
结构Empinfo
{
字符串名;
国际支付;
双倍小时;
双倍工资总额;
};
int main()
{
整数计数;
整数指数;
常数int arraysize=3;
Empinfo员工[安排];
对于(计数=0;计数cout
for(index=0;index
for(index=0;index通常,这句话:

index << arraysize

index通常,这句话:

index << arraysize

index您的第二个for循环写入错误

for (index = 0; index << arraysize; index++){ ... } 

for(index=0;index您的第二个for循环写入错误

for (index = 0; index << arraysize; index++){ ... } 

for(index=0;index
index
index
index哇,非常感谢。我看了一个愚蠢的错误。我也很感激你的建议,我会在以后的程序中记住这一点。就个人而言,为了可读性,我会更进一步,将两个循环放在不同的函数中(比如
input\u employees()
print\u employees()),或者在程序上下文中考虑的其他名称更清楚)。我也会使用标准容器,而不是原始数组。哇,非常感谢。我看了一个愚蠢的错误。我也很感激你的建议。我会在未来的程序中记住这一点。就个人而言,为了可读性,我会更进一步,将两个循环放在单独的函数中(比如
input\u employees()或<代码> PrtTyEngices()/<代码>,或您认为在程序上下文中更清楚的其他名称。我也将使用标准容器而不是原始数组。
for (int count = 0; count < arraysize; count++){
//Insert your logic here
}
for (int index = 0; index << arraysize; index++){
//Insert your logic here
}