this is a simple example of a problem I have been having with differing programs, i am using linux ubuntu 9.10 and codeblocks 8.02 .

this is the code

#include <iostream>

using namespace std;
int main()
{
    int hiya;
    cout<<"hello world \n";
    cin.get();
    cout<<"enter a number \n";
    cin>>hiya;
    cout<<"you entered \n"<< hiya;
    cin.get();
}

it compiles but show an error message "warning GDB: Failed to set controlling terminal: operation not permitted"

then the program runs

when it gets to the last cin instead of waiting for some input it exits

Recommended Answers

All 6 Replies

When you input a number into "hiya", you will press Enter. So the last cin reads '/n' and then the program exits.(Sorry, my english is poor.)

Add a cin.ignore() to ignore the newline control character

You can also do this

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int hiya;
    cout<<"hello world \n";
    getch();
    cout<<"enter a number \n";
    cin>>hiya;
    cout<<"you entered \n"<< hiya;
    getch();
}

>You can also do this: <snip conio.h crap>
You can do that...but don't teach it to others. Using conio.h is like bumping uglies with a fat chick. A lot of guys might do it, but they don't talk about it. Such is the way with bad programming practices.

commented: n/a +22

>You can also do this: <snip conio.h crap>
You can do that...but don't teach it to others. Using conio.h is like bumping uglies with a fat chick. A lot of guys might do it, but they don't talk about it. Such is the way with bad programming practices.

This may very well be the best post I have ever read on Daniweb. :icon_mrgreen:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.