Questions tagged [endl]

For issues relating to the std::endl output-only I/O manipulator.

endl is an output-only I/O manipulator. It inserts a newline character into an output sequence os and flushes the stream. It is defined in the header ostream and part of the namespace std. The behavior is equivalent to calling os.put('\n') and then os.flush().

Minimal example:

#include <iostream>

int main()
{
    std::cout << "Hello World" << std::endl;
    return 0;
}
79 questions
2
votes
4 answers

Function of type int not using return C++

If I have a function like this: int addNumbers(int x, int y) { return x + y; } and if I use it as such: cout << addNumbers(4, 5) << endl; It will return and print 9. Using the same cout line above, if I comment out or delete the return in…
Sam
  • 47
  • 3
2
votes
3 answers

Line spacing after endl and cout?

I noticed that in the following code: cout << "Please enter your number: "; cin >> Number; cout << "Is this spaced"; The output in the command window for C++ automatically puts "Is this spaced" in the next line. It spaces whatever is…
jlcv
  • 1,688
  • 5
  • 21
  • 50
2
votes
1 answer

How to get rid of endl from each Boost.Log line output?

I am new to Boost.Log in my c++ program. I create a logger called "simlog" and then I use following line to output my log text: BOOST_LOG( simlog ) << "some log info"; I don't want the default endl be appended to each of statement like this. I'd…
Wuwen Li
  • 81
  • 1
  • 6
1
vote
4 answers

C++ endl not printing new line when called from a method

New to C++ My understanding is endl will add a new line. So with the following piece of code: #include using namespace std; void printf(string message); int main() { cout << "Hello" << endl; cout << "World" <<…
1
vote
1 answer

Data type for std::string or std::endl

I have the following function template: #ifndef FUNCTIONS_H #define FUNCTIONS_H #include #include #include template void printall(std::vector& items, std::string sep = "\n") { for…
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50
1
vote
2 answers

Why some examples are using "endl" instead of "\n"?

Why some examples are using "endl" instead of "\n"? I heard that processing time of "endl" is longer than "\n" because "endl" has some flushing process. But, there are so many examples using "endl" on the internet. I wanna know why they're using…
hi-jin
  • 13
  • 2
1
vote
1 answer

XCode 4 only displaying cout statements with endl

I have a really weird issue with my cout statements. I've only tried this out with XCode 4. For instance, if I write, cout << "this works" << endl; cout << "this doesnt"; cout << memorySizeLimit << " blocks of memory available." << endl; I see all…
Nick Sweet
  • 2,030
  • 3
  • 31
  • 48
1
vote
1 answer

C++ cout and endl not printing correctly on terminal

My cout statements don't print correctly on my terminal for some reason. It creates space. When I have the following code: void Test::testSorted(){ vector unsorted = {4, 6, 5, 2, 1, 3}; vector sorted = {1, 2, 3, 4, 5, 6}; cout…
Pape Traore
  • 83
  • 2
  • 9
1
vote
1 answer

Custom stream flush type

I've had multiple questions on the matter of streams and stuff, but after thinking for a bit, I've come to the conclusion that all I need is a custom flush type. I want my stream to flush when it gets a new line. It saves having to type out…
Jookia
  • 6,544
  • 13
  • 50
  • 60
1
vote
2 answers

In C++ trying to write a newline after each operator overload cascade

this is a bit of a hard nut to crack. I'm writing a logging function that is trying to have a similar look to the std::cout So basically the goal is to have the following code do as commented log << "text"; // This would output "text\n"; log…
LemonCold
  • 96
  • 6
1
vote
1 answer

endl not creating new line in output file

This is my code now #include #include using namespace std; int main(int argc, char* argv[]) { // set up input file ifstream lInput; // declare an input file variable (object) ofstream lOutput; lInput.open(argv[1],…
Wing Hang Khoo
  • 41
  • 2
  • 10
1
vote
2 answers

Overloading endl compilation issue in GNU g++ 4.9.2

I'm having problem in compilation of the following code snippet while using GNU g++ 4.9.2 (used to compile ok in g++ 2.95.3) XOStream &operator<<(ostream &(*f)(ostream &)) { if(f == std::endl) { *this << "\n" << flush; …
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
1
vote
2 answers

Adding endl fixes code

In a program that I'm writing, a certain block of code only works correctly if I have a cout << endl statement at the beginning of it. If it is not there, the program doesn't segfault, but just gives a verifiably incorrect answer 100% of the time.…
amohan95
  • 11
  • 3
1
vote
2 answers

Comparing address of std::endl

I am inspecting a piece of existing code and found out it behaves differently when compiled with Visual C++ 9 and MinGW: inline LogMsg& LogMsg::operator<<(std::ostream& (*p_manip)(std::ostream&) ) { if ( p_manip == static_cast< std::ostream&…
Julien-L
  • 5,267
  • 3
  • 34
  • 51