在 Vim 中我输入命令 :w |制作
。我的 Makefile 如下所示:
all:
g++ -o main main.cpp
./main
main.cpp 如下所示:
#include <iostream>
using namespace std;
int main(){
cout << "Hello world!";
}
Vim 输出显示:
"main.cpp" 6L, 88C written
:!make 2>&1| tee /tmp/ve16mwu/0
g++ -o main maincpp
./main
(1 of 3): g++ -o main main.cpp
Press ENTER or type command to continue_
现在,当我退出 Vim 并运行可执行文件: $ ./main
后,输出会在终端中正常显示。
如果我在该行中添加一个换行符 \n
,如下所示: "Hello world!\n"
那么它就会很好地显示在 Vim 的输出中。
显然,在 Vim 中,如果末尾没有 \n
,输出将不会显示最后一行文本。有解决方法吗?
最佳答案
endl 来自 cplusplus.com :
Insert newline and flush
Inserts a new-line character and flushes the stream.
所以代码看起来像这样:
#include <iostream>
using namespace std;
int main(){
cout << "Hello world!" << endl;
return 0;
}
关于c++ - 为什么 Hello world 在 vim 中无法打印,但在 tty 中却可以打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31886396/