a console application in C++

A

arnuld

i want to create a console application in C++ . what can be the 1st
step ?

NOTE: i did use Google but that gives me some VC++ based links using
non-standard libraries.
 
J

Jim Langston

arnuld said:
i want to create a console application in C++ . what can be the 1st
step ?

NOTE: i did use Google but that gives me some VC++ based links using
non-standard libraries.

Download a compiler.
 
A

arnuld

Download a compiler.


seems like you did like my question. may be it is OT but i wanted to
write a console application in C++ without using any non-standard
libraries. i already have the compiler as i have Arch GNU/Linux: GCC
4.2.1
 
A

arnuld

seems like you did like my question. may be it is OT but i wanted to
write a console application in C++ without using any non-standard
libraries. i already have the compiler as i have Arch GNU/Linux: GCC
4.2.1

i meant: "seems like you did NOT like my question. may be it is OT
but i am not sure it is OT."
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

i want to create a console application in C++ . what can be the 1st
step ?

NOTE: i did use Google but that gives me some VC++ based links using
non-standard libraries.

What do you mean by console application? Roughly speaking there are two
kinds of applications, console and GUI and I don't think you've written
any GUI applications yet, which means that what you've done so far are
console applications.

If the input/output capabilities of cin/cout are not enough for your
needs you'll have to use some other, platform specific libraries since
there's nothing more advanced in standard C++. If this is what you want
ncurses might be worth looking into.
 
L

Lionel B

seems like you did like my question. may be it is OT but i wanted to
write a console application in C++ without using any non-standard
libraries. i already have the compiler as i have Arch GNU/Linux: GCC
4.2.1

What is your definition of "console application"? Is this a "console
application"? In a shell, do:

$ cat > hello.cpp
#include <iostream>

int main()
{
std::cout << "Hello world" << std::endl;
}

$ g++ -std=c++98 -pedantic hello.cpp -o hello
$ ./hello
Hello world

Note: the "-std=c++98 -pedantic" flags ensure that you are compiling
according to the current C++ standard without any GCC-specific extensions/
restrictions to the language.
 
A

arnuld

What do you mean by console application? Roughly speaking there are two
kinds of applications, console and GUI and I don't think you've written
any GUI applications yet, which means that what you've done so far are
console applications.

If the input/output capabilities of cin/cout are not enough for your
needs you'll have to use some other, platform specific libraries since
there's nothing more advanced in standard C++. If this is what you want
ncurses might be worth looking into.

sorry , i was at fault of not being clear. actually what we see at our
colleges/universities is theoretical foundation like make a programme
do this and do that. an average student from an average university
(unlike MIT, CMU etc) reads books and does the things and when he
enters in to the real-life software work like doing a job in industry
or working directly with customers, he gets shock at first because it
is *different*. same happened with me.

i want to create some console programme, i mean, anything that can be
called practical work and but which is general and approachable enough
for a fresher like me..

any ideas on that ?
 
A

arnuld

$ g++ -std=c++98 -pedantic hello.cpp -o hello
$ ./hello
Hello world

Note: the "-std=c++98 -pedantic" flags ensure that you are compiling
according to the current C++ standard without any GCC-specific extensions/
restrictions to the language.


Lionel, i use this.

g++ -ansi -pedantic -Wall -Wextra file.cpp

tell me if it is ok ?
 
A

asterisc

Lionel, i use this.

g++ -ansi -pedantic -Wall -Wextra file.cpp

tell me if it is ok ?

if you get the binary than is ok. On the other hand, if you are using
*nix based OS, man gcc or man g++ may help.
 
L

Lionel B

Lionel, i use this.

g++ -ansi -pedantic -Wall -Wextra file.cpp

tell me if it is ok ?

I used to use -ansi rather than -std=c++98 until it was pointed out to me
(on this ng) that -std=c++98 is probably more appropriate; ISO is an
international standardisation organisation, while ANSI is US only.

Apart from which I've actually just had a look at the GCC manual and it
doesn't say what -ansi does (if anything) for C++ - it only specifies the
ISO 1990 C standard, apparently...
 
P

Puppet_Sock

i want to create a console application in C++ . what can be the 1st
step ?

You need a compiler, linker, and the standard libraries.

You need some kind of ability to produce a source file.
That can be any convenient text editor that lets you
make a text file that your compiler can accept.

But this is off topic here. You need specifics on
how to run your local program, platform, compiler, etc.
If you have *language* questions, ask away. But how to
get your compiler etc. to produce an executable is off
topic here.

Look for help files or other docs with your compiler.
Look for news groups that have your compiler's name
in their name. Google for tutorials specific to your
particular compiler and platform.
Socks
 
D

Default User

Lionel B wrote:

I used to use -ansi rather than -std=c++98 until it was pointed out
to me (on this ng) that -std=c++98 is probably more appropriate; ISO
is an international standardisation organisation, while ANSI is US
only.

Apart from which I've actually just had a look at the GCC manual and
it doesn't say what -ansi does (if anything) for C++ - it only
specifies the ISO 1990 C standard, apparently...

From the Solaris man pages:

-ansi
In C mode, support all ISO C90 programs. In C++ mode,
remove GNU extensions that conflict with ISO C++.



Brian
 
J

jjds101

sorry , i was at fault of not being clear. actually what we see at our
colleges/universities is theoretical foundation like make a programme
do this and do that. an average student from an average university
(unlike MIT, CMU etc) reads books and does the things and when he
enters in to the real-life software work like doing a job in industry
or working directly with customers, he gets shock at first because it
is *different*. same happened with me.

What the hell are you on about? This comes off like the rantings of a
madman
i want to create some console programme, i mean, anything that can be
called practical work and but which is general and approachable enough
for a fresher like me..

any ideas on that ?

Sure. The first is that you aren't going to get anywhere writing
vague and incomprehensible questions in a newsgroup. If you want to
write a program then write one. Do the exercises in a textbook.
Solve a problem. Or, if you're beyond more trivial matters and yearn
for something more like real-world experience, find an open source
project. There are plenty of places where open source apps can be
found. Start with a smaller one, and get familiar with the code --
add a feature, fix a bug, whatever.
 
A

arnuld

What the hell are you on about? This comes off like the rantings of a
madman



Sure. The first is that you aren't going to get anywhere writing
vague and incomprehensible questions in a newsgroup. If you want to
write a program then write one. Do the exercises in a textbook.
Solve a problem. Or, if you're beyond more trivial matters and yearn
for something more like real-world experience, find an open source
project. There are plenty of places where open source apps can be
found. Start with a smaller one, and get familiar with the code --
add a feature, fix a bug, whatever.

TROLL alert....

*PLONK*
 
K

Kai-Uwe Bux

arnuld said:
i want to create a console application in C++ . what can be the 1st
step ?

Find a problem that your program should solve. Without a problem, it is hard
to tell whether the program is correct/useful.
NOTE: i did use Google but that gives me some VC++ based links using
non-standard libraries.

Which libraries you will need is something to be determined once you know
what you want the program to do.


Best

Kai-Uwe Bux
 
L

Lionel B

Lionel B wrote:



From the Solaris man pages:

-ansi
In C mode, support all ISO C90 programs. In C++ mode, remove
GNU extensions that conflict with ISO C++.

Right, just found that. So it seems that for C++ -ansi *is* actually
equivalent to -std=c++98. Well... according to the docs, the g++ default
is -std=gnu++98' which is "the same as -std=c++98 plus GNU extensions".
So I guess if you remove those extensions you're left with -std=c++98. Or
am I missing some subtlety here?

Upshot is I think I'll stick with the more straightforward "specify the
actual standard you want" approach; i.e. -std=c++98

Oh, and I'm told you need -pedantic too for strict standards-
compliance... now *that* has without doubt the most confusing man entry I
have ever seen. Ever.
 
B

BobR

On Jul 16, 11:05 pm, (e-mail address removed) wrote:
/* """
Sure. The first is that you aren't going to get anywhere writing
vague and incomprehensible questions in a newsgroup. If you want to
write a program then write one. Do the exercises in a textbook.
Solve a problem. Or, if you're beyond more trivial matters and yearn
for something more like real-world experience, find an open source
project. There are plenty of places where open source apps can be
found. Start with a smaller one, and get familiar with the code --
add a feature, fix a bug, whatever.

TROLL alert....

*PLONK*
""" */

Troll?!?!? Look who's calling the kettle black!!

(hint: You've been given simple example(s), but, you keep asking the same
question. That's what 'Trolls' do!)

Show what *you* have done, and explain what problem you have with it.

Whether it's a 'console' or 'GUI' is the compilers function, not 'C++'.
I put 'console apps' in a 'class', and instantiate(run) them in wxWidgets (a
GUI), to try/test them. That has nothing to do with 'C++' (though it's coded
in 'C++'. <G>).
 
A

arnuld

arnuld <[email protected]> wrote in message...
TROLL alert....

*PLONK*
""" */

Troll?!?!? Look who's calling the kettle black!!

BobR, a little search will tell you why i called "(e-mail address removed)" a
troll. i am posting here from some time. did i call anyone a troll
till yet, except "(e-mail address removed)"


???
(hint: You've been given simple example(s), but, you keep asking the same
question. That's what 'Trolls' do!)

ok , then call me a troll and *PLONK* me if you love to do so.
Show what *you* have done, and explain what problem you have with it.

Whether it's a 'console' or 'GUI' is the compilers function, not 'C++'.
I put 'console apps' in a 'class', and instantiate(run) them in wxWidgets (a
GUI), to try/test them. That has nothing to do with 'C++' (though it's coded
in 'C++'. <G>).

well, thanks but i will not try GUIs, ATM, i will focus on creating
classes.
 
J

James Kanze

[...]
Note: the "-std=c++98 -pedantic" flags ensure that you are compiling
according to the current C++ standard without any GCC-specific extensions/
restrictions to the language.

Note that the "-std=c++98 -pedantic" flags only affect the
compiler, and do *not* ensure that you are not including
non-standard headers or linking against non-standard libraries.
Something like:

#include <unistd.h>

int
main()
{
static char const h[] = "Hello, world!\n" ;
read( 1, h, sizeof(h)-1 ) ;
return 0 ;
}

will compile and link, with those flags, on my system, but is
anything but standard C++. (It is standard Posix, however:).)
On most (all?) Unix platforms, the C standard library and the
Posix standard library are merged in a way that makes it
impossible to separate them. (I'm not aware of an option for
VC++ which would make #include <windows.h> illegal either.)

With regards to the original question, concerning writing an
application in "standard" C++, the only real answer it to start
by documenting what is standard C++, and what isn't, and then
use a lot of personal discipline. Having two systems at your
disposition, one Windows and one Unix, and ensuring that all of
the code compiles and runs on both, helps a lot too. (But note
that both systems tend to have features to help migration from
the other, so it's not really a guarantee either.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top