简体   繁体   中英

Why does Hello world not print in vim but it works in tty?

In Vim I enter the command :w | make :w | make . My Makefile looks like this:

all:
    g++ -o main main.cpp
    ./main

main.cpp looks like this:

#include <iostream>
using namespace std;

int main(){
    cout << "Hello world!";
}

Vim output says:

"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_

Now after I quit Vim and run the executable: $ ./main then the output shows up fine in the terminal.

If I put add a newline \\n to the line like this: "Hello world!\\n" then it shows in Vim's output just fine.

Apparently, in Vim, the output won't show your last line of text if it doesn't have \\n on the end. Is there a workaround for this?

endl From cplusplus.com :

Insert newline and flush

Inserts a new-line character and flushes the stream.

So the code would look like this:

#include <iostream>
using namespace std;

int main(){
    cout << "Hello world!" << endl;
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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