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
0
votes
1 answer

cout does not print even with time delay

I expect cout to print "hello" and two seconds later " world". int t = time( NULL ); std::cout << "hello"; while( time(NULL) < (t + 2) ); std::cout << " world"; But instead, cout prints noting to screen until after two seconds later, then the…
ytobi
  • 535
  • 1
  • 9
  • 19
0
votes
1 answer

In c++, my program automatically goes to the next CIN prompt without letting the user add input

Here's my code: #include using namespace std; const int SENIOR_PRICE = 9; const int ADULT_PRICE = 12; const float CHILD_PRICE = 6.95; const float TAX_RATE = .06; int main() { string name; string address; int…
0
votes
1 answer

Segmentation Fault occurs if no std::flush

There are already some approaches for this question. ¹ ² ³ But this one is completely different! If I comment out std::flush line, Segfault occurs, but if I add this line, The Segmentation fault doesn't occur! int Stm32Serial::writeToSerial() { …
Orhan G. Hafif
  • 379
  • 5
  • 21
0
votes
1 answer

std::endl is not working with overloaded operator<< though dedicated non template function is implemented

I have some Logging::Logger class with the following functions: template const Logger& Logger::operator<<(const T& in) const { // ... return *this; } const Logger& Logger::operator<<(std::ostream& (*os)(std::ostream&)) { //…
Mugen
  • 8,301
  • 10
  • 62
  • 140
0
votes
1 answer

sending std::endl to stream gives memory address

Can somebody explain to me why this program sends an address to std::cout? #include #include #include std::ostream& stuff(std::ostream& o, std::string s) { o << s << std::endl; return o; } int main(){ …
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
0
votes
1 answer

Eclipse Luna C++ endl

I just started learning C++ and I noticed that when I do cout << "Some text" << endl; endl is not bold. I want to make sure that this is not a problem and it won't cause any future problems.
aku181
  • 1
0
votes
4 answers

how can I make a function ,declared as a string, end the line

I have a function that reads from a text file and the outputs the whole text file. It looks like this; string FileInteraction :: read() const { ifstream file; string output; string fileName; string line; string empty = ""; …
Blobiu5
  • 231
  • 1
  • 3
  • 6
0
votes
3 answers

Loop enters infinite loop if cout is missing

I have encountered something very strange. The code I am having trouble with is: int stringPos; int found1; while (stringPos < 1); { //start searching inString for framen starting at foundn and record found1 = inString.find(frame1,…
ktosayev
  • 17
  • 5
0
votes
0 answers

Adding a "endl" erases everything

First time I've ever encountered something like this. The code is supposed to take in a .txt file with data, perform some calculations and output a .txt file. I have quite a bit of experience with this kind of stuff but I have encountered…
ktosayev
  • 17
  • 5
0
votes
5 answers

Code works only with endl - very strange

I encountered a strange problem earlier. I was working at insertion in B-trees and I wrote a simple display function. I ran it and it didn't show anything in the console even though I inserted some values. I entered in the debug mode, I followed…
Sorin
  • 908
  • 2
  • 8
  • 19
0
votes
2 answers

Taking in a char vector from command line

I'm taking a command and I want to store it as a vector of characters. int main() { vector command; cout << "Reservations>>"; char next; cin >> next; while (next !='\n'){ command.push_back(next); cin >>…
Will Nasby
  • 1,068
  • 2
  • 16
  • 39
-1
votes
2 answers

printing results in multiple lines in python facing an error

In C++, we simply use std::endl in order to print a result in multiple lines. How can I do the same in Python? I use '\n' and I face a problem. If I wanted to write the code in C++, here's how I'd write it: #include #include int…
Liana
  • 314
  • 5
  • 15
-1
votes
2 answers

No match for ‘operator<<’ in std

I just started learning C++, and this test seemed like a good idea so i tried doing it, doesn't seem to work, and it really doesn't make sense why (to me). #include using namespace std; int myNum = 5; // Integer (whole…
user11347373
-2
votes
1 answer

a "?" before the string

I want to use strings to input the path of files: char** argv; char* mytarget[2]={ (char*)"‪D:\\testlas\\BigOne.pcd",(char*)"‪‪D:\\testlas\\SmallOne.pcd" }; argv = mytarget; for(int i=0;i<2;i++) { std::cout << "m.name: " << argv[i]…
AdamPengC
  • 29
  • 4
-3
votes
1 answer

std::endl, is there an equivalent in Python? (return + flush)

In C++, std::endl is used to add a return and flush the string. In Python, there is no need to use this special functionality, except for specific uses. One of the uses that may justify its use is when the output is redirected to a file, for…
Jeroen
  • 57
  • 1
  • 8