Using endl

Jun 5, 2019 at 1:16pm
I have only just started to learn C++ and i really would like some help please.
I typed out a multiple expression and ended it with endl but the correct answer appeared but it also had danny@ubuntu:~ along it. How can i separate the two?

1
2
3
4
5
6
#include <iostream>
using namespace std:

int main()
{
   cout << 355 / 5 << " " << 49 / 7endl;
Jun 5, 2019 at 1:25pm
You have to use the stream operator to send the endl to cout, just like everything you're sending.

I'm surprised the code you posted even compiles.
Jun 5, 2019 at 3:27pm
Hi,

It seems that you forgot to use the "<<" operator before the endl. The correct expression should be

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std:

int main()
{
   cout << 355 / 5 << " " << 49 / 7 << endl;
   return 0;
}


I hope this helps.
Jun 5, 2019 at 3:29pm
And it's
using namespace std;
not
using namespace std:
Look VERY carefully @christianwos (or just try to compile it!)
Last edited on Jun 5, 2019 at 3:30pm
Jun 5, 2019 at 3:31pm
Yes, sorry. I missed that one. Thanks for catching it.
Jun 5, 2019 at 4:33pm
Very big thank you to both christianwos and lastchance for taking the time out and helping a noob like myself.
It's not easy being a noob lol.
Jun 5, 2019 at 5:16pm
BTW, you only need to use endl if it is important to make sure your output is properly flushed (to file) at the end of every write. In almost all cases, a simple newline is enough.

1
2
3
  std::cout << "Hello world!\n";
  std::cout << "I'm " << 3 << ".\n";
  std::cout << "Number of nanobots: " << nanobot_count << '\n';

Hope this helps.
Topic archived. No new replies allowed.