Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5297 > unrolled thread

Running a simple c++ program

Started bylopez <lopezgilsinia@gmail.com>
First post2011-05-21 14:51 -0700
Last post2011-05-22 10:19 +1200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  Running a simple c++ program lopez <lopezgilsinia@gmail.com> - 2011-05-21 14:51 -0700
    Re: Running a simple c++ program Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-05-22 00:16 +0200
    Re: Running a simple c++ program Ian Collins <ian-news@hotmail.com> - 2011-05-22 10:19 +1200

#5297 — Running a simple c++ program

Fromlopez <lopezgilsinia@gmail.com>
Date2011-05-21 14:51 -0700
SubjectRunning a simple c++ program
Message-ID<7090140d-28d6-4129-84be-4b6d03cb82c4@y12g2000yqh.googlegroups.com>
Hi,

I tried running the following program using cygwin.
/** @file list0201.cpp */
/** Listing 2-1. Reading Test */
/// Read the program and determine what the program does.

#include <iostream>
#include <istream>
#include <limits>
#include <ostream>

int main()
{
    int min(std::numeric_limits<int>::max());
    int max(std::numeric_limits<int>::min());
    bool any(false);
    int x;
    while (std::cin >> x)
    {
        any = true;
        if (x < min)
            min = x;
        if (x > max)
            max = x;
    }

    if (x)
        std::cout << "min = " << min << "\nmax = " << max << '\n';
}

the command I used is

g++ list0201.cpp -o list0201 //to compile

and

./list0201 //to run


When I run I am getting a blank screen which does not seem to
terminate .. Can someone help me

[toc] | [next] | [standalone]


#5299

FromKai-Uwe Bux <jkherciueh@gmx.net>
Date2011-05-22 00:16 +0200
Message-ID<ir9dk7$s03$1@hoshi.visyn.net>
In reply to#5297
lopez wrote:

> Hi,
> 
> I tried running the following program using cygwin.
> /** @file list0201.cpp */
> /** Listing 2-1. Reading Test */
> /// Read the program and determine what the program does.
> 
> #include <iostream>
> #include <istream>
> #include <limits>
> #include <ostream>
> 
> int main()
> {
>     int min(std::numeric_limits<int>::max());
>     int max(std::numeric_limits<int>::min());
>     bool any(false);
>     int x;
>     while (std::cin >> x)
>     {
>         any = true;
>         if (x < min)
>             min = x;
>         if (x > max)
>             max = x;
>     }
> 
>     if (x)

should this be

      if (any)

>         std::cout << "min = " << min << "\nmax = " << max << '\n';
> }
> 
> the command I used is
> 
> g++ list0201.cpp -o list0201 //to compile
> 
> and
> 
> ./list0201 //to run
> 
> 
> When I run I am getting a blank screen which does not seem to
> terminate .. Can someone help me

Did you provide some input? The program is reading from std::cin and will 
wait for input; e.g., using a pipe, you could provide input as follows:

  echo 14 17 23 12 ¦ ./list0201


Best,

Kai-Uwe Bux

[toc] | [prev] | [next] | [standalone]


#5300

FromIan Collins <ian-news@hotmail.com>
Date2011-05-22 10:19 +1200
Message-ID<93qs3hF1bbU19@mid.individual.net>
In reply to#5297
On 05/22/11 09:51 AM, lopez wrote:
> Hi,
>
> I tried running the following program using cygwin.
> /** @file list0201.cpp */
> /** Listing 2-1. Reading Test */
> /// Read the program and determine what the program does.
>
> #include<iostream>
> #include<istream>
> #include<limits>
> #include<ostream>
>
> int main()
> {
>      int min(std::numeric_limits<int>::max());
>      int max(std::numeric_limits<int>::min());
>      bool any(false);
>      int x;
>      while (std::cin>>  x)
>      {
>          any = true;
>          if (x<  min)
>              min = x;
>          if (x>  max)
>              max = x;
>      }
>
>      if (x)
>          std::cout<<  "min = "<<  min<<  "\nmax = "<<  max<<  '\n';
> }
>
> the command I used is
>
> g++ list0201.cpp -o list0201 //to compile
>
> and
>
> ../list0201 //to run
>
>
> When I run I am getting a blank screen which does not seem to
> terminate .. Can someone help me

How do you end your input?  You are looping until end of file condition 
on cin, so you need to input an end of file character (^D on a Unix like 
shell).

-- 
Ian Collins

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web