Re: [Dev-C++] A very singular problem in Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jonathan W. <jon...@gm...> - 2007-04-02 12:44:20
|
Indeed, in a general case, (and esp. in Unix), there are tools that are
easily used this way (and are definitely designed to).
In the case of system('pause'), however, it's really an overkill, since the
command only does something trivial to do in code (plus the overhead...)
Jonathan
On 4/2/07, Per Westermark <pw...@ia...> wrote:
>
> Calling system functions isn't necessarily extra unsafe, and it isn't as
> simple as being bad if the OS does some of the work.
>
> When developing for unix, the majority of all command-line utilities are
> intended for interaction with other applications. Either externally - by
> letting the user piping data between the applications - or internally, by
> making use of popen() to directly read the output of other applications.
>
> It should be noted, that in an M$ world, it is practically impossible to
> write a truly portable application. Why? M$ have decided to rename a large
> number of standard C functions - giving them an initial '_' character in
> the name.
>
> /Per W
>
> On Mon, 2 Apr 2007, Jonathan Winterflood wrote:
>
> > Indeed, system('pause') is rather messy (plus it's not really portable)
> > I usually do a system('pause') as a quick fix in the early stages of
> setting
> > up a program, I guess I'll use cin.get() from now on :)
> >
> > This would make the program so:
> >
> > #include <iostream>
> > using namespace std;
> > int main()
> > {
> > //say hello :)
> > cout<<"Hello World!\n";
> >
> > //wait for user keypress
> > int pressed = cin.get();
> >
> > //ignores an extra keypress
> > cin.ignore();
> >
> > /*
> > do some more things here
> > */
> > }
> >
> > But why should I ignore an extra character in the input, since the
> cin.get()
> > will eat the key the user pressed?
> > could it be a '\n' vs. '\r\n' issue ?
> >
> > Jonathan
> >
> > On 4/2/07, Amy...@ao... <Amy...@ao...> wrote:
> > >
> > > you really should not use system calls in a program unless you really
> > > need it. They are unsafe, and it sort of gets the OS to do the work
> for you.
> > > It is always safer and better practice to use cin.get() instead of
> > > system("pause")
> > >
> > > Yiu can add cin.ignore() under cin.get() if you use cin in the program
> as
> > > an input object, but not all compilers need this, the mingw one does
> however
> > >
> >
>
>
--
<Morpheus> linux, c'est une question de VI ou de MORE
|