PDA

View Full Version : How to run cosol based application in Qt creator



phillip_Qt
5th March 2010, 05:24
Hi ALl,
I cannot run consol based application using Qt creator. Plz tell me if my procedure is wrong. Below also i've pasted snipset of my code.

1. open new project
2. select Qt console based application.
3. write the code.

Its not recognising std library functions.


//#include <QtCore/QCoreApplication>
#include <iostream>

using namespace std;
//int main(int argc, char *argv[])
//{
// QCoreApplication a(argc, argv);
//
// return a.exec();
//}



#include <stdio.h>

void dec_bin(int number);

int main(void)
{
int input = 0;

printf("Digit (0-255): ");
scanf("%d", &input);

(input >= 0) && (input < 256) ? dec_bin(input) : std::exit(1);

return 0;
}

void dec_bin(int number)
{
int x, y;
x = y = 0;

for(y = 7; y >= 0; y--)
{
x = number / (1 << y);
number = number - x * (1 << y);
printf("%d", x);
}

printf("\n");
}


Thank you all.

Braunstein
5th March 2010, 13:38
Hello,

std::exit is in cstdlib. You must include this.
Your code is nearly pure C. Do you want to write C or C++?