You are not logged in.

#1 2011-07-07 00:33:02

Ascaronth
Member
Registered: 2011-07-07
Posts: 5

[SOLVED] Qt and new lines in console output. C/C++

First of all, since this is my first post, I think an "Hello, and thank you for this wonderful distro" is something I ought to say.

Now on topic. This code

#include <iostream>
using namespace std;

int main()
{
    int nN1;

    cout << "Hello, insert number? ";
    cin >> nN1;
    cout << "Nice, you gave me " << nN1 << ", tyvm <3";

    return 0;
}

produces the following output.

[name@name ~]$ QTPrograms/Test-build-desktop/Test
Hello, insert number? 7
Nice, you gave me 7, tyvm <3[name@name ~]$

I didn't put any endl or \n, so I find the output rather interesting. I suppose the new line is because I press return but I don't remember this behaviour in my previous experiences with windows, ubuntu and elementaryOS.
It's not that big of a deal though, so if you know why it does this now and/or how to solve it, good, else it's not important, really.

By the way I would never code something like that. I would at least spell "thank you very much" correctly, and have some kind of protection if the user put something other than a number there. It reads a 0 if you do. On windows and ubuntu it would just screw everything up and start printing the last string ad infinitum, in this case that would be "Hello, insert number? ". Another interesting behaviour.

Since I'm here, another couple questions. Any way to change the Tools -> Options -> Environment -> Terminal option to something other than xterm? If I put "lxterminal -e" it flashes for a split second and then it's gone. All I've found googling it is a bug report and some other people complaining about the same thing, but maybe some of you could have figured this out, who knows?

I wrote couple but I can't seem to remember the other one so...

Last edited by Ascaronth (2011-07-07 18:51:35)

Offline

#2 2011-07-07 06:31:41

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: [SOLVED] Qt and new lines in console output. C/C++

Just some hints so you can get your answers quicker:

  • Your program and questions don't have anything to do with Qt. All you're
    using is plain C++. Adapt your topic to attract more potential helpers.

  • As to the "Tools -> Options -> Terminal" question: You definitely should
    mention what program you're referring to.

Oh, and welcome to the Arch linux community smile

Last edited by the_isz (2011-07-07 06:32:10)

Offline

#3 2011-07-07 06:52:49

linux-ka
Member
From: ADL
Registered: 2010-05-07
Posts: 232

Re: [SOLVED] Qt and new lines in console output. C/C++

Try

std::cout<<"blablabla"<<std::endl;

Offline

#4 2011-07-07 13:57:06

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] Qt and new lines in console output. C/C++

@Ascaronth:  I don't really understand your problem.  Are you actually wondering about the new line appearing in the output after you entered "7"?

Last edited by lunar (2011-07-07 13:57:20)

Offline

#5 2011-07-07 16:02:44

Ascaronth
Member
Registered: 2011-07-07
Posts: 5

Re: [SOLVED] Qt and new lines in console output. C/C++

the_isz wrote:

As to the "Tools -> Options -> Terminal" question: You definitely should
mention what program you're referring to.

Well, what I actually meant was "Qt creator", that's the program I'm referring to. And you're right, this is plain C++. As I said with Qt I meant Qt creator IDE, sorry for my bad terminology, I'm still young and stupid.

lunar wrote:

@Ascaronth:  I don't really understand your problem.  Are you actually wondering about the new line appearing in the output after you entered "7"?

Exactly. Sorry if this wasn't very clear. When I enter 7 and press enter, the cursor goes on a new line. I did not encounter such behaviour on windows, ubuntu, and elementaryOS. It's not a big problem, but I would like to know why is that happening.

Offline

#6 2011-07-07 17:54:32

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] Qt and new lines in console output. C/C++

@Ascaronth:  I'm quite surprised that you can't remember this behaviour, because it is really standard:  You hit enter, and the terminal emulator – apparently xterm in your case – inserts a new line.  That is just, what "enter" is supposed to do in a terminal, just like hitting "Shift+A" is supposed to insert an upper case A smile  No terminal emulator works any different, not even on Windows.  You really should have seen this before.

Any way, this isn't related to your program at all.

Last edited by lunar (2011-07-07 17:55:05)

Offline

#7 2011-07-07 18:51:11

Ascaronth
Member
Registered: 2011-07-07
Posts: 5

Re: [SOLVED] Qt and new lines in console output. C/C++

Oh well, I suppose it's just my memory playing trick on me then. It's been a couple of months since I last programmed anything, so that could be it... Oh well, I'll mark this as solved, sorry for the useless thread hmm

Offline

Board footer

Powered by FluxBB