You are not logged in.
Hi,
In KDevelop4, I have this C++ test program:
#include <iostream>
#include <cstdlib>
using namespace std;
int multiply(int a, int b);
int main(int argc, char **argv) {
cout << "Helloasdf, world! abla" << endl;
cout << "line 2" << endl;
cout << "a line without endl";
cout << "multiply: " << multiply(4, 10);
return 0;
}
int multiply(int a, int b) {
int antwoord = a * b;
return antwoord;
}When launching, it says this:
Helloasdf, world! abla
line 2
a line without endlmultiply: 40However, when launching in debug mode, it says this:
Helloasdf, world! abla
line 2When I add a endl to line 2, it does output the next line. When I set breakpoints, stepping over the lines doesn't do anything.
Is this a bug?
Offline
Is this a bug?
Probably not. Using endl flushes the stdout buffer, and presumably optimisation stops it being flushed automatically when your program exits. If you really don't want a newline at the end, just call cout.flush()
Last edited by PirateJonno (2010-07-13 23:20:23)
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline
When I change the code to this:
#include <iostream>
#include <cstdlib>
using namespace std;
int multiply(int a, int b);
int main(int argc, char **argv) {
cout << "aHelloasdf, world! abla" << endl;
cout << "line 2" << endl;
cout << "a line without endl"; // it doesn't print this line in debug mode when there is no endl
cout.flush();
cout << "multiply: " << multiply(4, 10);
cout.flush();
return 0;
}
int multiply(int a, int b) {
int antwoord = a * b;
return antwoord;
}It still doesn't output the last lines when debugging.
Offline
Streams are automatically flushed when a program terminates, so the cout.flush() don't change anything.
I'm guessing that KDevelop expects the program to end with a newline, otherwise it will overwrite the last line. This is a reasonable expectation -- some shells do this too. So, just end your program with a newline, unless it has to output data in a really structured format for some reason.
Offline
Don't know how I managed to misinterpret "debug mode" as "optimisation", not that it makes me any less wrong ![]()
Anyway taviantor's suggestion sounds reasonable
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline
I'm guessing that KDevelop expects the program to end with a newline, otherwise it will overwrite the last line. This is a reasonable expectation -- some shells do this too. So, just end your program with a newline, unless it has to output data in a really structured format for some reason.
It doesn't overwrite, it just stops outputting.
But OK, I guess I can live with it if it's just the way KDevelop interprets shell output commands.
Offline