gpt4 book ai didi

c++ - 为什么这个程序提示我 'pressy any key to continue' ?

转载 作者:行者123 更新时间:2023-11-28 03:57:45 25 4
gpt4 key购买 nike

我正在尝试将网页中的数据复制到结构数组中,并在生成数据之前按“名称”排序。当我运行这个程序时,它说按任意键继续?

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

struct productJewelry
{
string name;
double amount;
int itemCode;
double size;
string group;
};

int main()
{
// declare variables
ifstream inFile;
int count=0;
int x=0;

productJewelry product[50];

inFile.open("jewelry.txt"); // file must be in same folder
if (inFile.fail())
cout << "failed";
cout << fixed << showpoint; // fixed format, two decimal places
cout << setprecision(2);

while (inFile.peek() != EOF)
{
// cout << count << " : ";
count++;
inFile>> product[x].itemCode;
inFile>> product[x].name;
inFile>> product[x].size;
inFile>> product[x].amount;
inFile>> product[x].group;
// cout << product[x].itemCode << ", " << product[x].name << ", "<< product[x].size << ", " << product[x].amount << endl;
x++;
if (inFile.peek() == '\n')
inFile.ignore(1, '\n');
}

inFile.close();
string temp;
bool swap;
do
{
swap = false;
for (int x=0; x<count;x++)
{
if (product[x].name>product[x+1].name)
{
//these 3 lines are to swap elements in array
temp=product[x].name;
product[x].name=product[x+1].name;
product[x+1].name=temp;
swap=true;
}
}
} while (swap);

for (x=0; x< count; x++)
{
//cout<< product[x].itemCode<<" ";
//cout<< product[x].name <<" ";
//cout<< product[x].size <<" ";
//cout<< product[x].amount<<" ";
//cout<< product[x].group<<" "<<endl;

}

system("pause"); // to freeze Dev-c++ output screen
return 0;
} // end main

最佳答案

它说“按任意键继续”,因为这就是 system("pause") 调用的 pause 程序所做的。

它不会输出任何其他内容,因为您已注释掉所有输出语句

关于c++ - 为什么这个程序提示我 'pressy any key to continue' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2783026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com