简体   繁体   English

从终端运行C ++程序。 在同一终端窗口中获​​取输出

[英]Run C++ program from terminal. Get output in same terminal window

When I run my c++ programs from Terminal (Mac OS X), output from programs is shown in a new Terminal window. 当我从终端(Mac OS X)运行我的c ++程序时,程序的输出显示在一个新的终端窗口中。

What can I do to prevent the new window, and just have the programs' output straight in the window thats already open? 我该怎么做才能阻止新窗口,只是在已经打开的窗口中直接输出程序的输出?

I believe gcc comes with the XCode tools package. 我相信gcc附带了XCode工具包。

If you have gcc installed, open terminal window, cd to the directory where you put your cpp file, and type: 如果您安装了gcc,请打开终端窗口,cd到您放置cpp文件的目录,然后键入:

g++ myTestFile.cpp -o main; ./main

Replace 'myTestFile' by the name of your file, naturally. 当然,用文件名替换'myTestFile'。 you can also rename the 'main' which is just the name of the compiled module, which you need to run by typing ./main to retrieve the output of your code. 您还可以重命名'main',它只是已编译模块的名称,您需要通过键入./main来检索代码的输出。

I guess you are using the open command. 我猜你正在使用open命令。

$ open foo

This will open a new terminal window. 这将打开一个新的终端窗口。

Don't use the open command if you want the program to run in the current terminal window. 如果希望程序在当前终端窗口中运行,请不要使用open命令。

$ foo

† You should obviously leave out the dollar sign. †你显然应该省略美元符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM