c++ - 为什么 Hello world 在 vi​​m 中无法打印,但在 tty 中却可以打印?

标签 c++ linux vim terminal makefile

在 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 在 vi​​m 中无法打印,但在 tty 中却可以打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31886396/

相关文章:

java - 将 C++ 项目迁移到 Java,保护实现细节

java - CentOS上安装ActiveMQ打不开admin等网页

linux - 在 Bash 脚本中嵌入密码

Linux Intel 64bit 汇编事业部

c++ - LNK2001:为 x64 平台构建时无法解析的外部符号

c++ - 类模板可以是函数吗

Vim 自动命令 : writing a read-only file?

c++ - 如何在 vim 的颜色方案文件中更改运算符 (+ - */< >) 的颜色

c++ - HDF5 中的嵌套复合数据类型

vim - 函数是否比 Neovim 中的命令快?