0

I am a total newbie to C++ and I need to have 3 line of text and after every line I have to ask the user to press enter to continue. How can I do it?

Here is the code that I have so far:

#include <iostream>
using namespace std;

int main()
{
    std::cout << "Es esmu dators.";
    std::cout << "Es zinu C++.";
    std::cout << "C++ ir programmesanas valoda";
}
Jongware
  • 22,200
  • 8
  • 54
  • 100

2 Answers2

3

You can use getchar() after each line. To use getchar() you must include cstdio.

Example code:

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
    std::cout << "Es esmu dators.\n";
    getchar();
    std::cout << "Es zinu C++.\n";
    getchar();
    std::cout << "C++ ir programmesanas valoda\n";
}
2

From this answer:


Several ways to do so, here are some possible one-line approaches:

Use getch() (need #include ).

Use getchar() (expected for Enter, need #include ).

Use cin.get() (expected for Enter, need #include ).

Use system("pause") (need #include ).

PS: This method will also print Press any key to continue . . . on the screen. (seems perfect choice for you :))


You should also perform a quick search on the site to see if your question has been asked before, going forward.

Community
  • 1
  • 1
Ironcache
  • 1,719
  • 21
  • 33