std::endl or /n

What do i end my input output streams with

endl flushes the buffer

while newline dosent

what dose flushing the buffer ezactly mean please explain like very simply im really confused also what are the uses of flushing a buffer(whatever it means pls tell me what it means) and do professional programs use std::endl or /n

also i got a error for a very simple programme here is the code (tell me what i did wrong)

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>

int main ()
{

   std::cout << "Test" <<std::endl;
   std::cout << "new" <<std::endl;



    return 0;

}


What did i do wrong i use two ostream objects ending it with endl but when i change it to /n it somehow works

it does execute but shows a blank with a error code saying returning bunch of numbers

i appreciate anyone who is even bothering to click on this post it still means a lot :) have a good day programmers
just tested in Xcode, works fine. what IDE are you using?

and by the way:

instead of putting std:: in front of everything, just put this
using namespace std;
underneath this
#include <iostream>

also, there is no difference between endl; and /n... i prefer endl because it doesn't obstruct text in the brackets, and endl just looks nicer.

can you give me the error message?

thanks
-ASCII14
Flushing output buffer means that stream content will be forced to be writthen to disc/output to screen/sent to the net.

So if you use endl (or just .flush()), your text will be shown on screen in any case. Otherwise it will be output when your library decides so.

also i got a error for a very simple programme
Your program is working. Tell exactly, what error says.

instead of putting std:: in front of everything, just put this
Do not do that if you thinking about getting a job in IT. In medium to large projects you are almost guaranteed to run into problems with using directive.
Last edited on
Uhhhh

instead of putting std:: in front of everything, just put this
using namespace std;

I cant really do that its really bad

pretend you had to namespaces that means the using while have a collision and give unknowns errors

search it up and write why using namespace is bad btw

im using codeblocks and it returns on the output stream blank with a return code of 1965290633
Uhhhh

instead of putting std:: in front of everything, just put this
using namespace std;

I cant really do that its really bad

pretend you had to namespaces that means the using while have a collision and give unknowns errors

search it up and write why using namespace is bad btw

im using codeblocks and it returns on the output stream blank with a return code of 1965290633


Ok now tell me .Who made another function called exactly cout ??
@mini

Thx you answered my question SO BASSCIALYY

if i had

std::cout << "dog";

it wont output but if i write

std::cout << std::endl;

it will output it im i correct outputs any data left in the memory
it wont output but if i write
It will be output when your library decides it is time. Usually it happens before reading from stream, when buffer is full and from time to time. Many manual flushes will slow down program, because it will not be able to make use of advantages of buffered input.
Can you give me a example C++ programmer explaining it with comments around it i really want to learn C++ so i can became a great programmer like you
I have answered your PM.
If I got your question right, you might find helpful these online language references:
http://www.cplusplus.com/reference/
http://en.cppreference.com/
They contain information about language features and standard library. Also you might want (after you finish with beginner level stuff) to get a copy of C++ standard. It is basically is a description how language should work. It is very hard to read nad it is better to not try to read if you don't yet get hold of C++.
Thx should i learn C after C++ or if i learn C++ i will already now most of C
That depend. If you would want to learn C after you good In C++, go for it. It will help you to understand low-level stuff. If you will decide to move to higher level languages, that is fine too. It is too early to think about that.
Topic archived. No new replies allowed.