我们如何在命令行开发环境中编写程序?
我一直在IDE中编写代码,我刚刚读到还有一个命令行开发环境,其中代码是在DOS中编写的。我用Google搜索但没有找到有关如何使用命令行开发环境的结果。我的操作系统是Windows XP.我非常感谢你帮助我在DOS下编写hello world程序并解释如何运行它。
I have been writing my code in IDE,I just read that there also existed a Command Line Development Environment in which the code is written in DOS.I googled but found no results on how to use the command line development environment.My OS is Windows XP.I would be very thankful for your help me write the hello world program in DOS and also explain how to run it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您只需使用您喜欢的任何文本编辑器来创建 C 源文件,然后调用编译器命令行来编译和链接程序(通常,IDE 正是这样做的,但在幕后)方式)。如何调用命令行取决于您使用的具体工具链。
您可能还需要为特定的编译器工具链设置环境(可能需要设置正确的路径和各种其他环境变量)。
对于 Visual C++,可以使用 Visual Studio 安装的批处理文件来设置环境:
调用编译器可以像以下一样简单:
或对于 C++(由于某种原因,如果您不给它一个选项,它会发出非致命警告)配置有关如何实现异常的详细信息):
详细信息非常依赖于您使用的编译器 - 您应该阅读该编译器的文档。
此外,您使用的选项取决于您的具体情况和需求。脚本/批处理文件和/或 makefile 可以帮助您管理可能需要使用的选项的复杂性。
You simply use whatever text editor you like to create the C sourse file(s) then invoke the compiler command line(s) to compile and link the program (typically, an IDE is doing exactly that, but in a behind-the-scene manner). How the command line is invoked depends on the exact toolchain you're using.
You might also need to set up an environment for you particular compiler toolchain (the right paths and various other env variables might need set up).
For Visual C++ the environment might be set up using a batch file installed by Visual Studio:
Invoking the compiler could be as simple as:
or for C++ (for some reason it issues a non-fatal warning if you don't give it an option configuring details about how it should implement exceptions):
The particulars are very dependent on the compiler you're using - you should read the docs for that compiler.
Also, the options you use depend on your particular situation and needs. Scripts/batch files and/or makefile can help you manage the complexity of the options you might need to use.
DOS 还没有死……还没有!
fahad
有多种方法可以在 DOS 中输入代码(请参阅下面的编辑)。
(1) 您可以将击键直接发送到文件
您可以通过将CON(控制台)的输出重定向到文件来实现此目的。此方法的唯一奇怪之处在于,当您完成时,您可以通过输入 CTRL-Z 来结束“会话”。
这是基本的,但事情就是这样的。
首先,假设您想在屏幕上显示“Hello World”,只需要一个包含以下两行的简单批处理文件:
'@echo off' 通常出现在所有批处理文件。它只是指示命令解释器在执行(或解析)时不要显示每个命令。
在我们开始之前还有一件事。在整个答案中,我将假设您的程序名为“helloworld.bat”。
逐行输入以下行,并在每行末尾按 ENTER 键:
当您按 CTRL-Z 组合键时,将显示“^Z”(不要忘记按 ENTER 键)。
当您在CTRL-Z之后按ENTER键时,DOS会显示熟悉的“1个文件已复制”消息。
现在,您只需输入程序名称即可执行批处理文件程序,如下所示:
DOS 将显示以下内容:
没有比这更基本的了。
(2) 可以使用DOS的EDIT程序
这是90年代中期保留下来的基于DOS的IDE。只需输入以下命令:
EDIT 将在同一个 DOS 窗口中打开。当您关闭EDIT时,您将再次返回到DOS。
编辑也可以使用鼠标。
编辑打开后,输入以下两行代码:
然后,单击[文件]、[保存],输入:'helloworld.bat' 在“文件名”输入字段中,如果需要,可以使用鼠标在“目录:”窗格中更改目录,然后单击[确定]。要返回 DOS,请单击[文件]、[退出]。
编辑版本4.5(我认为)是上下文相关的,并使用不同的颜色来分隔关键字、不同的数据类型、符号等来显示代码。
(3) 使用Windows 的内置记事
本 这很简单。在命令提示符下,输入以下命令:
然后记事本将启动。它是一个简单的文本编辑器,可以在输入小程序时完成工作。
(4)使用记事本++。它是免费的!
Notepad++是程序员的选择。它是免费的,充满有用的功能并且可定制。通过搜索“notepad++”在网上找到它。
DOS is not dead.... yet!
fahad
There are a number of methods by which you can enter code in DOS (see EDIT further on down).
(1) You can send keystrokes directly to a file
You do this by redirecting output to CON (the console) to a file. The only oddity of this method is that you end the 'session' by entering a CTRL-Z when you are finished.
It's basic, but this is how it goes.
Firstly, suppose you want to display "Hello World" on the screen, a simple batch file containing the following two lines is all that is required:
The '@echo off' is commonly found at the start of all batch files. It simply instructs the command interpretter NOT to display each command as it is being executed (or parsed).
One more thing before we start. Throughout this answer, I will assume your program is named 'helloworld.bat'.
Enter the following lines one after the other pressing the ENTER key at the end of each line:
The '^Z' is displayed when you press the CTRL-Z key combination (don't forget to press the ENTER key as well).
When you press the ENTER key after CTRL-Z, DOS displays the familiar '1 File(s) copied' messege.
You can now execute the batch file program by simply entering the program's name like this:
And DOS will display the following:
It can't get any more basic than that.
(2) You can use DOS' EDIT program
This is a DOS based IDE retained from around the mid-90's. Simply enter the following command:
And EDIT will open in the same DOS window. When you close EDIT, you are returned back to DOS again.
EDIT also works with your mouse.
Once EDIT opens, enter the following two lines of code:
Then, click on [File], [Save], type: 'helloworld.bat' in the "File Name" input field, use your mouse to change directories in the "Directories:" pane if you want to, then click [OK]. To return to DOS, click [File], [Exit].
EDIT version 4.5 (I think) was context-sensitive and displayed code using different colours to seperate key word, different data type, symbols etc.
(3) Use Windows' built-in Notepad
This is simple. At the command prompt, enter the following command:
And Notepad will fire up. It's a simple text editor and does the job when entering small programs.
(4) Use Notepad++. It's FREE!!
Notepad++ is the programmer's choice. It's free, full of useful features and customisable. Find it on the net by searching for "notepad++".
根据您的评论,“只是一些知识,所以我可以说我知道一种无需 IDE 即可进行编程的方法”,我会说学习编写简单的批处理文件。它们可以从资源管理器运行,但它们是 DOS 时代的遗留物。
启动命令提示符窗口(开始->运行->“cmd”),这将打开一个窗口并显示提示符,很可能是“c:\”或其他路径。
键入以下命令(后跟 )
您应该看到:
现在,使用您想要的任何编辑器,创建一个文本文件,并将该命令作为唯一的行。将文件命名为“hello.bat”。当您在命令提示符下时,您可以像这样执行批处理文件:
您现在已经使用 DOS 命令行进行编程。有关更多命令等,请从帮助系统开始。
这将显示批处理文件的所有可用命令。
Microsoft 有一个在线参考 在这里。
From your comment, "Just some knowledge so I can say that I know one way to do programming without IDE" I would say learn to write simple batch files. They can be run from Explorer but they exist as a holdover from the DOS days.
Start a command prompt window (Start->Run->'cmd'), this will open a window and show a prompt, most likely "c:\" or some other path.
Type the following command (followed by )
You should see:
Now, using whatever editor you'd like, create a text file with that command as the only line. Name the file "hello.bat". When you are at the command prompt you can execute the batch file like so:
You have now programmed using the DOS command line. For more commands and such, start with the help system.
Which will display all the available commands for your batch file.
Microsoft has an online reference here.
DOS 对于所有实际用途来说都已经死了。在 Windows 下,您的选择归结为以下几点:
DOS is dead for all practical purposes. Under Windows your options boil down to the following:
兄弟,使用 gcc 编译器在任何文本编辑器中编写你的代码,然后在 Windows shell 中编译你的代码,或者你可以说命令行环境。
看!
提示:>> gcc source_file_name.c
这个命令编译你的代码,
如果有任何错误,您将显示行号,
现在,每个程序默认都会创建名为 a.exe 的 exe 文件。
获取程序的输出,
提示:>> a.exe
O/P
你好世界!
要更改 exe 文件的名称,还有一个命令。
Bro, use gcc compiler for which write ur code in any text editor then compile ur code in windows shell or u can say command line environment.
Look!
Prompt:/> gcc source_file_name.c
This command compiles ur code,
If there is any error, u will get dispalyed with line numbers,
now, every program creates its exe file by the name a.exe by default.
To, get the output of ur program,
Prompt:/> a.exe
O/P
Hello World!
To change the name of the exe file there is also a command..