C++ 不是 运行 正确输出
C++ not run an output properly
这是我的代码片段
void start_hang(){
cout << "*********************\n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << "*********************\n";
cout << "=====================\n";
}
但这是我的输出
*********************
*********************=====================
这是我的另一个尝试:
- 没有使用命名空间
- 在每个输出前加上
std::
void start_hang(){
std::cout << "*********************\n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << "*********************\n";
std::cout << "=====================\n";
}
还是不行。
也许我使用 class 错误?
这是我的完整代码:
这是我的编译器:
g++ (tdm64-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我正在使用 g++ game.cpp
进行编译,这导致了错误 hmm
然而,在我执行 g++ -g game.cpp -o game.exe
之后,它给出了一个输出并且程序按预期工作
代码正确 there's no issue with it。问题在于您编译和执行的方式。
在类 UNIX 系统上,gcc 输出二进制文件的默认名称是 a.out(这也是一种古老的可执行格式)
-o
file
Place the primary output in file file
. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
If -o
is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.
在 Windows 上默认为 a.exe。您必须使用 -o
选项指定名称,否则您将不得不 运行 a.exe
。因此,如果您使用 g++ game.cpp
然后 运行 game.exe
进行编译,那么您正在执行一些在
之前编译的旧错误 game.exe
这是我的代码片段
void start_hang(){
cout << "*********************\n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << "*********************\n";
cout << "=====================\n";
}
但这是我的输出
*********************
*********************=====================
这是我的另一个尝试:
- 没有使用命名空间
- 在每个输出前加上
std::
void start_hang(){
std::cout << "*********************\n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << " \n";
std::cout << "*********************\n";
std::cout << "=====================\n";
}
还是不行。
也许我使用 class 错误?
这是我的完整代码:
这是我的编译器:
g++ (tdm64-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我正在使用 g++ game.cpp
进行编译,这导致了错误 hmm
然而,在我执行 g++ -g game.cpp -o game.exe
之后,它给出了一个输出并且程序按预期工作
代码正确 there's no issue with it。问题在于您编译和执行的方式。
在类 UNIX 系统上,gcc 输出二进制文件的默认名称是 a.out(这也是一种古老的可执行格式)
-o
file
Place the primary output in file
file
. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.If
-o
is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.
在 Windows 上默认为 a.exe。您必须使用 -o
选项指定名称,否则您将不得不 运行 a.exe
。因此,如果您使用 g++ game.cpp
然后 运行 game.exe
进行编译,那么您正在执行一些在
game.exe