Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Running a simple c++ program

Reply
Thread Tools

Running a simple c++ program

 
 
lopez
Guest
Posts: n/a
 
      05-21-2011
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
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      05-21-2011
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Question regarding running .py program Caroline Hou Python 23 11-16-2012 06:38 AM
running a simple ruby program Sagy Drucker Ruby 1 01-10-2012 07:55 PM
Running a program (gperf) inside another C program Alexander Mahone C Programming 4 05-26-2008 09:31 PM
running another program from a C++ program Lorenzo Bettini C++ 3 09-24-2005 10:05 AM
Help !I want to write a program to count the running time of another program freehomesp@yahoo.com.cn C Programming 1 08-12-2005 06:13 AM



Advertisments