*对于那些有这个问题的人,这是我的命令的问题。确保您编译和运行程序的命令是正确的!
我在youtube上看教程。
我做的和 op 做的完全一样,我得到了不同的输出。
我是 C++ 新手,我正在使用 Xcode 运行代码。
这是代码:(同样,这不是我的,而是来自 youtube 教程视频)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int input[100];
int x = 0;
int fail = 0;
int pass = 0;
fstream textfile;
textfile.open("exam.txt");
while(! textfile.eof()) {
textfile >> input[x];
cout << input[x] << endl;
if(input[x] < 50) {
fail++;
}
else {
pass++;
}
x++;
}
textfile.close();
cout << fail << "students out of " << (fail + pass) << "did not pass the exam." << endl;
return 0;}
它应该打印成绩。
但这就是我在 Xcode 上运行它时得到的。
0
0
0
0
0
0
0
0
1606415288
32767
1606415720
32767
1606415720
32767
2003953588
1294056514
104
1
1606415312
32767
25240
1
1606415288
32767
1606415312
32767
25248
1
1606415288
32767
1606415312
32767
1606415720
32767
25264
1
1606415304
32767
1606415720
32767
1606415720
32767
6144
1
1910210376
32767
1606416728
32767
0
0
0
0
0
0
0
0
0
0
1606416544
32767
2003953588
1294056514
1606416544
32767
-1988827167
32767
0
0
1
0
1606416904
32767
0
0
这只是输出的一部分。它不会终止。
此外,当我尝试在 linux 上运行它(sshed 到学校 linux 机器)时,
我收到以下错误:
@@?!@8 @ @@@@@?88@8@@@?? ??`?`?? ``?TT@T@DDP?tdPP@P@DDQ?tR?td??`?` /lib64/ld-linux-x86-64.so.2GNUGNU?Yd?`˫sP???*??"b!!?? (E?L?
CyIk? ^Q#y??K@??'?[?
@3P
@ `??
@libstdc++.so.6__gmon_start___Jv_RegisterClasses_ZNSt8ios_base4InitD1Ev_ZNSt13basic_fstreamIcSt11char_traitsIcEEC1Ev_ZNSt13basic_fstreamIcSt11char_traitsIcEE5closeEv_ZNSirsERi_ZNSt13basic_fstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode__gxx_personality_v0_ZSt4cout_ZNSolsEi_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6__ZNSt13basic_fstreamIcSt11char_traitsIcEED1Ev_ZNSolsEPFRSoS_E_ZNKSt9basic_iosIcSt11char_traitsIcEE3eofEv_ZNSt8ios_base4InitC1Evlibgcc_s.so.1_Unwind_Resumelibc.so.6__stack_chk_fail__cxa_atexit__libc_start_mainGCC_3.0GLIBC_2.4GLIBC_2.2.5CXXABI_1.3GLIBCXX_3.4 P&y
xui ?ӯk?t)??`? ` ` ` ` `( `0 8 ` @ ` p60ii
H `
P `
` `h `p `x `? `H??c????H???5? ?%? @?%? h??????%? h??????%? h??????%? h?????%? h?????%? h?????%? h?????%? h?p????%? ?`????%? h ?P????%? h
?@????%? h
?0????%? h
?????%z h?????%r h??????%j h?????1?I??^H??H???PTI???@H??0@H??
@????????H?H?? H??t??H?Ð????????????UH??SH??=0 uK?`H?* H???`H??H??H9?s$fDH??H? ???`H?? H9?r??? H?[]?fff.?H?= UH??t?H??]`??]Ð?UH??SH???dH?%(H?E?1?Dž????Dž????Dž????H??????H???T???????H???????@H???????|H??0?????????Hc?H??H?H??????H??H???$?????????H????0????ƿ? `?Y?????
@H???
?????????H????0?????1 ???????????????????H??????H???????????d???H??????H???R???????????????????????ƿ? `??????%@H????????H???????6@H?????????
@H???`????H??????H?????????H?U?dH3%(t$?H??H??????H???????H??H???L????????H???[]?UH??H???}??u??}?u*?}???u!??!`?6????P
@?? `??!`H?????????UH?????????]?UH??}??u??U??E? ?]Ð???H?l$?L?d$?H?-? L?%? L?l$?L?t$?L?|$?H?\$?H??8L)?A??I??H??I???k???H??t1?@L??L??D??A??H??H9?u?H?\H?l$L?d$L?l$ L?t$(L?|$0H??8???Ð?????????????UH??SH?H H???t??`DH???H?H???u?H?[]Ð?H??_???H??exam.txtstudents out of did not pass the exam.D????`?????s?????????????????0p???XzRx
$H??? FJ
O ??;*3$"D8???A?C
我使用了这个命令: g++ main.cpp -o output.out 我的命令有问题吗?
太感谢了!!!