我想知道这个题目的代码那里错误了?
这是题目:编写程序,从文件“NumberFile.txt”中读取数据(文件中有360个数字),按照从小到大排序后输出到文件SortedNumber.txt
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main()
{
double Num[360];
int i,j;
ifstream infile("NumberFile.txt", ios::in);
if (!infile)
{
cerr << "open error!" << endl;
exit(1);
}//输入文件
ofstream outfile("SortNumber.txt");
if (!outfile)
{
cerr << "open SortNumber.txt error!" << endl;
exit(1);
}//输出文件
for (i = 0; i < 360; i++)
{
infile >> Num[i];
cout << Num[i] << " ";
}
for (int i = 0; i < 360 - 1; i++)//开始冒泡排序,总共排序轮数为 元素个数-1
{
for (int j = 0; j < 360 - i - 1; j++)//内层循环对比 次数=元素个数-当前轮次-1
if (Num[j]>Num[j + 1])
{
double temp = Num[j];
Num[j] = Num[j + 1];
Num[j + 1] = temp;
}
}
cout << endl;
for (i = 0; i<360; i++)
{
outfile << Num[i] << "\n";
cout << Num[i] << endl;
}
infile.close();
system("pause");
return 0;
}
我运行时一直不出现运行框?返回值还是1?不懂?
附这是NumberFile.txt内容
11.3099
-21.8014
11.2847
-21.7788
11.2088
-21.7107
11.0812
-21.5962
10.9002
-21.4337
10.6634
-21.2207
10.3673
-20.9541
10.0075
-20.6295
9.5781
-20.2412
9.07124
-19.7816
8.47663
-19.2407
7.78026
-18.6049
6.96254
-17.8548
5.99477
-16.9623
4.83183
-15.8827
3.39482
-14.5377
1.51733
-12.7615
-1.33737
-10.0182
-1.6714
-9.69372
1.67538
-12.9119
4.05883
-15.1608
6.07554
-17.037
7.88898
-18.7043
9.57162
-20.2353
11.1628
-21.6695
12.6866
-23.031
14.1586
-24.3359
15.5901
-25.5953
16.9888
-26.8173
18.3607
-28.0083
19.7104
-29.1728
21.0415
-30.3147
22.3568
-31.4369
23.6585
-32.5422
24.9485
-33.6324
26.2282
-34.7093
27.4991
-35.7745
28.762
-36.8292
30.0179
-37.8746
31.2674
-38.9115
32.5112
-39.941
33.7499
-40.9637
34.9837
-41.9804
36.2131
-42.9916
37.4384
-43.998
38.6598
-45
39.8775
-45.9981
41.0917
-46.9928
42.3024
-47.9845
43.5099
-48.9734
44.7141
-49.9601
45.9151
-50.9447
47.113
-51.9277
48.3077
-52.9092
49.4993
-53.8896
50.6878
-54.8692
51.8731
-55.8481
53.0552
-56.8266
54.2341
-57.8049
55.4098
-58.7833
56.5821
-59.7619
57.7511
-60.741
58.9167
-61.7207
60.0788
-62.7012
61.2375
-63.6828
62.3925
-64.6654
63.544
-65.6494
64.6918
-66.6349
65.8359
-67.622
66.9762
-68.6109
68.1126
-69.6017
69.2453
-70.5946
70.374
-71.5896
71.4987
-72.587
72.6195
-73.5868
73.7363
-74.5892
74.8491
-75.5942
75.9578
-76.6021
77.0624
-77.6128
78.163
-78.6265
79.2594
-79.6433
80.3518
-80.6633
81.44
-81.6866
82.5242
-82.7133
83.6042
-83.7433
84.6802
-84.7769
85.7522
-85.8141
86.8201
-86.855
87.884
-87.8995
88.944
-88.9478
90
-90
91.0522
-91.056
92.1005
-92.116
93.145
-93.1799
94.1859
-94.2478
95.2231
-95.3198
96.2567
-96.3958
97.2867
-97.4758
98.3134
-98.56
99.3367
-99.6482
100.357
-100.741
101.373
-101.837
102.387
-102.938
103.398
-104.042
104.406
-105.151
105.411
-106.264
106.413
-107.38
107.413
-108.501
108.41
-109.626
109.405
-110.755
110.398
-111.887
111.389
-113.024
112.378
-114.164
113.365
-115.308
114.351
-116.456
115.335
-117.607
116.317
-118.763
117.299
-119.921
118.279
-121.083
119.259
-122.249
120.238
-123.418
121.217
-124.59
122.195
-125.766
123.173
-126.945
124.152
-128.127
125.131
-129.312
126.11
-130.501
127.091
-131.692
128.072
-132.887
129.055
-134.085
130.04
-135.286
131.027
-136.49
132.016
-137.698
133.007
-138.908
134.002
-140.122
135
-141.34
136.002
-142.562
137.008
-143.787
138.02
-145.016
139.036
-146.25
140.059
-147.489
141.088
-148.733
142.125
-149.982
143.171
-151.238
144.226
-152.501
145.291
-153.772
146.368
-155.052
147.458
-156.342
148.563
-157.643
149.685
-158.958
150.827
-160.29
151.992
-161.639
153.183
-163.011
154.405
-164.41
155.664
-165.841
156.969
-167.313
158.331
-168.837
159.765
-170.428
161.296
-172.111
162.963
-173.924
164.839
-175.941
167.088
-178.325
170.306
178.329
169.982
178.663
167.238
-178.483
165.462
-176.605
164.117
-175.168
163.038
-174.005
162.145
-173.037
161.395
-172.22
160.759
-171.523
160.218
-170.929
159.759
-170.422
159.371
-169.992
159.046
-169.633
158.779
-169.337
158.566
-169.1
158.404
-168.919
158.289
-168.791
158.221
-168.715