Duoas 1,025 Postaholic Featured Poster

I tested pretty carefully on the example data you gave me.
What does the header for your data actually look like?

The loop I gave you only stops when it finds a line whose very first character is a dash '-' . If it doesn't find such a line, then it will scan through the entire file and your vector of certificates will never get filled.

If that is not the case, post back with the actual header for your file and any changes to the code you made.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You should have yourself a little class that represents your data, and overload the extraction operator to handle it.

Since I was really bored today, I wrote a program for you. Change the parts you need to match your assignment.

Notice that there are several classes in use here.

  • date_t
    A very simple date-handling class. There are a lot of other ways it could have been implemented, including simply wrapping the <ctime> stuff, but I wanted to play. It demonstrates some useful STL usage...
  • certificate_t
    This is your certificate data. Notice that it is templated on whether or not you wish to print verbosely, since I did not know how you want your data output. (If that is overload for you, then just delete all the "verbose" stuff.) The difference is in the insertion operator beginning on line 255, where you can see the if statement choosing based on what to print. I also had to overload the default and copy constructors for the class in order to be able to change a non-verbose certificate into a verbose one. Again, there are other ways to do this, this is just one.
  • expired
    This is a little helper class to select through the list of certificates. See main() for how it is used.

A couple of other things to note:

  • Insertion (<<) operators are tricky things to play with. Notice how I output to a stringstream and then send that to the …
m4ster_r0shi commented: cool (^_^) +7
mike_2000_17 commented: you should ask for a pay check! +11
Duoas 1,025 Postaholic Featured Poster

>>Don't #include C header files in your header files

Oohh I didn't know it's wrong to do that.

It isn't wrong to do that.

You don't want to #include anything more than you absolutely must, but the whole point of #includes is to make stuff work.

How, for example, would the <sstream> header be able to specify anything useful without #including <string> ? You would have to duplicate information, and that is worse...


I always explain namespaces like having two friends named Jennifer. One is Jennifer Logan and the other is Jennifer Warner. When neither is present, I need to indicate that I am speaking about one or the other by using her full name. When one is present, I just call her "Jennifer", and I refer to the other by her full name. If both are present, I must again specify exactly who I mean.

Hope this helps.

Mouche commented: Awesome analog for namespaces. +6
Duoas 1,025 Postaholic Featured Poster

Google works pretty good for me.
http://www.google.com/search?q=directsound+vs+tutorial
Is this not what you are looking for?

Duoas 1,025 Postaholic Featured Poster

Why I can't compile without the using namespace std line?

You can, but you have to qualify things.

Things like cout and string and transform() are all defined in the std namespace. If you don't using namespace std (to tell the compiler that all the stuff in std is also in the current namespace) then you must explicitly tell the compiler where to find it.

#include <iostream>

void uses_everything()
  {
  using namespace std;  // import everything from 'std' into current
  cout << "everything in std is used here.\n";
  }

void uses_cout()
  {
  using std::cout;  // import only 'cout' from 'std' into current
  cout << "Only 'cout' was used here.\n";
  }

void uses_nothing()
  {
  std::cout << "Nothing was used.\n";
  }

int main()
  {
  uses_everything();
  uses_cout();
  uses_nothing();
  return 0;
  }

There is a second issue here. Make sure that you never using anything in header files.


The file extension on header files has nothing to do with g++, but everything to do with the library author.

The C++ standard requires that certain headers take the form <iostream> and <algorithm> and <cstdio> and the like.

Some people think that was stupid, and use things like ".hpp", as in <boost/any.hpp> and the like.

Some librarys were written in C, or they follow the C convention, and have the ".h" extension, as in "regex.h" and the like.

Just about anything is possible, but most compilers do require you to stick to one of the mentioned conventions.

Duoas 1,025 Postaholic Featured Poster

Is this thread one of those that is going to be resurrected once a year forever more?

Yep.

Duoas 1,025 Postaholic Featured Poster

If I'm using a Mac, how am I supposed to put a line in the file that contains a '\r' (without it being treated as an EOL)?

Duoas 1,025 Postaholic Featured Poster

Do you mean that you are trying to handle something like when the user enters "flubbix" instead of a number?

Make yourself a little function to get numbers from the user:

#include <iostream>
#include <string>
#include <sstream>

template <typename T>
std::istream& get_number( std::istream& ins, T& x )
  {
  // Read a line (terminated by ENTER/RETURN key press) from the user
  std::string s;
  std::getline( ins, s );

  // Get rid of any trailing whitespace
  s.erase( s.find_last_not_of( " \f\n\r\t\v" ) + 1 );

  // Read it into the target type
  std::istringstream ss( s );
  ss >> x;

  // Check that there is nothing left over
  if (s.length() == 0 || !ss.eof())
    {
    ins.setstate( std::ios::failbit );
    }

  return ins;
  }

//
// SOMETHING TO SEE IT WORK
//
int main()
  {
  using namespace std;

  double d;

  cout << "Enter a number> ";

  if (!get_number( cin, d ))
    {
    cout << "Hey! That was not a number!\n";
    return 1;
    }

  cout << "Good job! Your number was: " << d << ".\n";
  return 0;
  }

Remember the following cardinal rule:

The user will always press ENTER/RETURN at the end of every input!

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Your constructor should look like this:

Nation::Nation(string lName):
    name(lName), land(20), food(50), troops(15), gold(100),
    people(100), farmers(0), merchants(0), blacksmiths(0)
{
    // Body left empty
}

The list of things are not functions (which is why the compiler is complaining, because you are using them like functions) but member fields.

The list is called an initialization list.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Inno Setup has pretty complete documentation, but it is not very easy to take in all at once. You need to open the section on "Pascal Scripting" and take a read through it.

There are a variety of ways to handle what you wish to do, but you will probably just want to do something like the following:

Create an InitializeInstall() event handler in your code section, which checks if the file is needed, whether the user wants to download and install it (and continue), continue (without the download -- presumably because the file is already present on the user's system), or cancel. Do as directed.

You can use the functions listed in the "Support Functions Reference" to do things like check Windows version information, check whether specific files are installed, display messages to the user, etc.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Microsoft function names are not very creative (which is a good thing).

GetDC()

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No, the map sorts on the key. If you change the key then the sort order changes. You state that the key is the movie name for both maps, so the order should not be different.

If you want a different sort criteria, then your map type should specify one as a template argument...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Line 2 should declare ch as an int.

Duoas 1,025 Postaholic Featured Poster

For use on Windows platform only:

#include <windows.h>

...

void SetColors( unsigned fg, unsigned bg )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ),
    ((bg & 0xF) << 4) + (fg & 0xF)
    );
  }

See Microsoft's Console Functions for more.

If you plan to write cross-platform code then I would suggest looking at NCurses... let me know if that is the case.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You will also need to explicitly instruct Windows to associate your port with a COM device. You can find instructions here.

Finally, you would be aware that only "COM1" through "COM9" are specifiable like that. If you associate a port with a larger device number, you'll have to specify it with a string like "\\\\.\\COM24" , as described in this article. The same string will work for the normal port numbers also, as in "\\\\.\\COM2" .

Hope this helps.

Ancient Dragon commented: nice useful info. +17
Duoas 1,025 Postaholic Featured Poster

Wait, you only want the first line -- so what're all those loops for?

ifstream musicCheck( "..." );
if (musicCheck.is_open())
{
  // The file is open, so read the very first line
  getline(musicCheck,songsUnlockedString);
  // Now that we've read it, we're done. No loops needed.
}
musicCheck.close();

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Your operators should have the following prototypes: Alsation operator + ( const Alsation& x ); Alsation& operator = ( const Alsation& y ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Hint: have a double variable that holds the previous value in the array, and a variable for the current value of the array. Subtract the current from the previous. Also, remember that 2 minus 9 is -7, but the difference is an absolute number: 7. (You'll need to use fabs().)

Also, don't rely upon knowing the size of your array. Pass it as argument to your function. void ArraySub(double* MainArray, unsigned n) Finally, if your program terminates properly, you should return 0; Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Use a std::stringstream:

void Set_Actors(ifstream &fin){
     string s;
     getline(fin, s);
     istringstream ss(s);
     for (unsigned n=0; getline(ss, Actors[n], ','); n++){
          ss >> ws;
     }
}

Notice how I use >> ws instead of ignore(...) ... it is more robust that way.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You need to write a lambda (you can either name one or use letrec) to compare two colors (proper lists of three numeric elements). Once done that you can sort your colors any of the usual ways.

Remember, you can build your list by adding elements either at the front or at the back. So a list like:
(1 9 7 2)
can be sorted: [b]([/b]sort '(1 9 7 2)[b])[/b] 1 (9 7 2) --> (1 < 9) --> (cons 1 [b]([/b]sort '(9 7 2)[b])[/b]) 9 (7 2) --> (9 > 7) --> (cons [b]([/b]sort '(7 2)[b])[/b] 9) 7 (2) --> (7 > 2) --> (cons [b]([/b]sort '(2)[b])[/b] 7)) 2 () --> 2 producing the result: (1 . ((2 . 7) . 9)) Now just flatten the pairs into a proper list and you are set.

(This is just one way to do it.)

Duoas 1,025 Postaholic Featured Poster

Google around "PE32".

Duoas 1,025 Postaholic Featured Poster

I don't like the current direction, though. I think embarcadero screwed up on a few things... Alas.

Duoas 1,025 Postaholic Featured Poster

You forgot give us your email so we can send it there after we have written your program.

Nick Evan commented: This thread makes me laugh :) +16
Duoas 1,025 Postaholic Featured Poster

It is probably because you've got a cin >> foo; somewhere else in your program.

You can't blithely mix >> and getline() input, because the user will always press ENTER at the end of every input.

Your inputs, then, should look like this:

// get something with >>
int n;
cin >> n;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

// get something with getline()
string s;
getline( cin, s );

If you do it like this then you will have read everything the user typed, up-to and including the ENTER key he pressed at the end.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Unless you are still trying to delete something you shouldn't (which is everything except your original line 38), then please post your complete code again.

Duoas 1,025 Postaholic Featured Poster

Fix your indentation and you'll see what is going wrong.
Good luck!

Duoas 1,025 Postaholic Featured Poster

...also, you need to check to see if the number would be less than zero after subtracting, not before: num = (num >= subtrahend) ? (num - subtrahend) : 0; If your number is signed, you can just use the proper <algorithm> num = max( 0, num - subtrahend ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are mis-naming things, and that is not helping. Also, you are using a list composed by (pointer to (pointer to car)). Why not just use a list composed by (pointer to car)? That is, you are using an array of (pointer to car) instead of just an array of car.

Finally, the difference is that you are not being careful when mixing >> and getline(). The first leaves the ENTER key in the input, while the second does not. After using >> you can get rid of the ENTER key by using cin.ignore().

unsigned numberOfCars;
cout << "How many cars would you like to catalog? ";
cin >> numberOfCars;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

car* listOfCars = new car[ numberOfCars ];

for (unsigned i = 0; i < numberOfCars; i++)
{
	cout << "Please enter the make: ";
	getline( listOfCars[ i ].make );
	cout << "Please enter the year made: ";
	cin >> listOfCars[ i ].year;
	cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
}

Remember, the user will always press ENTER after every input.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

A stack is just a "last-in, first-out" (or LIFO) structure. You can make one with an array:

const unsigned STACK_SIZE = 50;
unsigned stack_used = 0;
int stack[ STACK_SIZE ];

To add an item, just stick it at the end of the stack and bump the number of items used:

if (stack_used < STACK_SIZE)
  stack[ stack_used++ ] = 42;

To remove an item, just decrement the number of items used:

if (stack_used > 0)
  stack_used--;

The reason it is called a stack is because of the way it works. Consider when you go to your local buffet restaurant. At the end of the lines of food there are stacks of plates (probably the cool ones that sink-into/rise-out-of the counter). You can add a plate by sticking it on the top. You can remove a plate by taking it off of the top.

The item on the top of the stack is always stack[ stack_used - 1 ] .

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Make your menuFuntion() return whether or not the user elects to continue. So main would look something like:

bool menuFunction();

int main()
{
	while (menuFunction())
		;
	cout << "Goodbye.\n";
	return 0;
}

Your exit() function is a dangerous name conflict, especially just to write something before quitting. Hence, you can get rid of it as I have above. (Or just rename it to something consistent, like exitFunction() or goodbyeFunction().)

You might also want to check whether the user entered '9' before asking for the numerator and denominator. "I want to quit." --> "Great! What numerator would you like to use?" Not exactly friendly.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

All user input is terminated by pressing the ENTER key. Users expect this.

If you want to get individual key presses, you must do an OS-specific thing: disable buffered input.

On Windows, use SetConsoleMode().
On POSIX, use tcsetattr().

Be sure that you only do this when the user expects it, and that you restore things to line-buffered input before your program terminates.

All this is a bit more complicated than you may think. The NCurses library is a good, cross-platform system for writing programs that do this kind of thing.

POSIX: http://www.gnu.org/software/ncurses/
Windows: http://pdcurses.sourceforge.net/
Getting Started: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

Good luck!

Duoas 1,025 Postaholic Featured Poster

You need to read up at The Function Pointer Tutorials

Good luck!

Duoas 1,025 Postaholic Featured Poster

Hi all. I have some questions that may cover multiple forums, but I think this is the most appropriate.

I have been working on my wife's new website. You can see its current state here:
http://home.comcast.net/~mlyn7576/signandgrow/
The following questions apply both to the home page and one of the sub-pages.


Question 1
How likely is it that a non-CSS capable browser will access the site?
Keep in mind that the common users for Melissa's site will be non-technical people. For that reason, I've had to make some significant concessions to IE and javascript (instead of the beautiful, pure-CSS site I originally designed before I realized how horribly broken IE is).

I have tested the browser in FF, Opera, Safari, IE6 & IE7, Netscape, and Lynx.

The site is designed to degrade gracefully if the user's browser does not support CSS. While nice, this prevents the page from properly validating as HTML 4.01 Strict, since I use a few Transitional elements in the tags. But I cannot declare it as Transitional or IE 7 goofs up.

Obviously, I'm a fair novice at this HTML wizardry. The main reason for the no-CSS powers is to support textual browsers like Lynx. Does anyone know percentages for the likelihood that I really need the page to downgrade to non-CSS?


Question 2
Is it possible to position an element as "fixed" in one dimension only?
One of the design ideas …

Duoas 1,025 Postaholic Featured Poster

This is the C++ forum, not the C forum. You cannot expect C answers in a C++ forum.

Nevertheless, AD did answer your question sufficiently. The answer works the same way, except you use a FILE* instead of an istream.

If you can use FILE*s, you can do it. Please pay attention.

Duoas 1,025 Postaholic Featured Poster

You've pretty much learned all there is to it: the STL streams library does not handle non-binary streams very well.

If you plan to seek[[b]g[/b]|[b]p[/b]]() / tell[[b]g[/b]|[b]p[/b]]() at all, use binary I/O.

Sorry.

Duoas 1,025 Postaholic Featured Poster

On POSIX systems, use poll() (or select()) to check to see if there is user input pending.

On Windows systems, use WaitForSingleObject().

I know this example is for windows, but you can easily modify it to work using the POSIX equivalent (Kubuntu update hosed my system and I haven't fixed it yet, so I'm not going to mess with modifying this example today):

#include <iostream>
#include <string>
using namespace std;

#include <windows.h>

int main()
  {
  string s;
  HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );

  cout << "I am going to count to 10.\n"
          "Press ENTER at any time to stop.\n";

  for (unsigned counter = 1; counter <= 10; counter++)
    {
    cout << "\r   \r" << counter << " " << flush;

    // Wait for one second on the standard input.
    // If standard input is waiting, we're done.
    if (WaitForSingleObject( hStdIn, 1000 ) == WAIT_OBJECT_0)
      {
      cout << "\r   \r> ";
      getline( cin, s );
      break;
      }
    }

  if (!s.empty())
    {
    cout << "(You entered \"" << s << "\".)\n";
    }

  cout << "OK. All done.\n";

  return 0;
  }

This kind of "is keypressed" function is easy to do:

#include <windows.h>

bool iskeypressed( int ms )
  {
  return WaitForSingleObject(
    GetStdHandle( STD_INPUT_HANDLE ),
    ms
    );
  }
// POSIX
#define INFINITE (-1)

#include <unistd.h>
#include <poll.h>

bool iskeypressed( int ms )
  {
  struct pollfd pls;
  pls.fd = STDIN_FILENO;
  pls.events = POLLIN | POLLPRI;
  return poll( &pls, 1, ms );
  }

On older BSD systems you may have to …

MrYrm commented: thanks for the great info +1
Duoas 1,025 Postaholic Featured Poster

What you want to do is an OS-specific function. What Operating System are you using?

Duoas 1,025 Postaholic Featured Poster

It is not entirely clear what you want to do, but if it is just copying specific elements of a container to another container, use the remove_copy_if() STL algorithm, along with a predicate that decides what it is you wish to not copy, and a back_insert_iterator<> to stick the results in the target container.

For example:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;

bool not_uppercase_nor_number( char ch )
  {
  // Remember, because the STL algorithm works by copying
  // everything except what we want, we want to list the
  // things we want in a negative way:
  return !(
      (isalpha( ch ) && isupper( ch ))
    || isdigit( ch )
    );
  }

int main()
  {
  string src = "Hello 1st there!";
  string dst;

  cout << "source = " << src << endl;

  // Copy all UPPERCASE letters and all DIGITS (but nothing else)
  remove_copy_if(
    src.begin(),
    src.end(),
    back_inserter( dst ),
    &not_uppercase_nor_number
    );

  cout << "result = " << dst << endl;

  return 0;
  }

You should see:

source = Hello 1st there!
target = H1

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No exception is thrown when you enter bad input. Instead, the input stream is set to a fail state. Check using the good() member function.

int n;
  cout << "Enter a number: " << flush;
  while (true)
    {
    cin >> n;
    if (!cin.good())
      {
      cin.clear();  // clear the error state
      cin.ignore( numeric_limits <streamsize> ::max(), '\n' );  // get rid of the bad input
      cout << "Enter a NUMBER ONLY: " << flush;  // complain
      }
    else break;  // otherwise, input worked OK, so escape the loop
    }
  cout << "Good job! You entered the number " << n << ".\n";

Hope this helps.

[edit] Hey, I just noticed you are using C. This is the C++ forum. In C, you need to check the result of scanf() to see how many items were scanned.

Duoas 1,025 Postaholic Featured Poster

Your professor is a jerk. (Anyone who would instruct his students to do something before doing it himself the same way students would is a jerk.) Using system( "color 1B" ); doesn't work -- that modifies the color of the entire console window.

Since you are on Windows, there are two (good) options to you. The first is to use the Win32 SetConsoleTextAttribute() function like vmanes instructed you. You can set both foreground and background colors with it.

Here is an example program:

#include <iostream>
#include <limits>
using namespace std;

#include <windows.h>

int main()
  {
  HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  WORD color;
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  GetConsoleScreenBufferInfo( hStdOut, &csbi );

  for (unsigned f = 0; f < 16; f++)
    {
    for (unsigned b = 0; b < 16; b++)
      {
      // On Windows, the color is just this: very easy to calculate.
      color = (b << 4) + f;
      SetConsoleTextAttribute( hStdOut, color );
      cout << " A ";
      }
    SetConsoleTextAttribute( hStdOut, csbi.wAttributes );
    cout << endl;
    }

  cout << "Press ENTER to quit..." << flush;
  cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

  return 0;
  }

(Clearing the screen is another trick. See here or here for more.)


The other option is to use the Curses library, which is a portable terminal handling library. For Windows versions, check out PDCurses.

Here is a sample program that uses it:

#include <curses.h>

int main()
  {
  int f, b, color_index;

  initscr();
  start_color();

  for (f …
Duoas 1,025 Postaholic Featured Poster

I've done that so many times it is just obnoxious now.

Part of my first compilation process is just going through and fixing all the stupid typos I've made.

Duoas 1,025 Postaholic Featured Poster

It has to do with what type of character input the compiler expects and what kind of character data your program expects. Surprisingly, the two may be different.

Unfortunately, anything outside the ASCII range (0..127) is not safe to put in a string/character literal.

Alas.

Duoas 1,025 Postaholic Featured Poster

Whenever you get errors, it is typically a good idea go to the line with the error on it. On line 63 you have:

cout<<"The paycheck for the salesperson will be approximately ">>payCheck>>" "

The error message says it has a problem with '>>' on that line. Perhaps you meant to use some other operator? ;)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Will not work since you are using getline ( requires return ).

Argh, OK, I missed that non-linebuffered bit.

Nevertheless, rather than use a derelict library like <conio.h>, why not use the proper method? The Windows API works just fine.

#include <iostream>
using namespace std;

#include <windows.h>

//----------------------------------------------------------------------------
// Here is a little class that uses the Win32 functions to provide some
// nice, friendly input options.
//
struct key_t
  {
  enum mode_t { unbuffered, normal };

  HANDLE hStdIn;
  DWORD  initial_mode;

  //..........................................................................
  key_t()
    {
    hStdIn = GetStdHandle( STD_INPUT_HANDLE );
    if (!GetConsoleMode( hStdIn, &initial_mode ))
      {
      hStdIn = INVALID_HANDLE_VALUE;
      }
    else 
      {
      mode( unbuffered );
      }
    }

  //..........................................................................
  ~key_t()
    {
    if (isatty())
      {
      mode( normal );
      }
    }

  //..........................................................................
  bool isatty() const
    {
    return hStdIn != INVALID_HANDLE_VALUE;
    }

  //..........................................................................
  void mode( mode_t mode )
    {
    SetConsoleMode( hStdIn, (mode == unbuffered) ? 0 : initial_mode );
    }

  //..........................................................................
  bool ready( unsigned milliseconds = 0 )
    {
    return WaitForSingleObject( hStdIn, milliseconds ) == WAIT_OBJECT_0;
    }

  //..........................................................................
  int get()
    {
    INPUT_RECORD inrec;
    DWORD        count;
    ReadConsoleInput( hStdIn, &inrec, 1, &count );
    return inrec.Event.KeyEvent.wVirtualKeyCode;
    }

  };

//----------------------------------------------------------------------------
int main()
  {
  key_t key;
  int   ch = -1;

  //..........................................................................
  // Make sure the standard input is attached to a human being.
  //
  if (!key.isatty())
    {
    cout << "Hey foo! You gotta be a HUMAN to use this program!\n";
    return 1;
    }

  //..........................................................................
  // Get a key only if pressed within ten specific intervals.
  // 
  cout << "I am going to count to 10.\n"
          "Press any key …
Duoas 1,025 Postaholic Featured Poster

No, don't bind the processor like that. Use one of the wait functions, like the one I suggested.

Here is a simple example:

#include <iostream>
#include <string>
using namespace std;

#include <windows.h>

int main()
  {
  string s;
  HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );

  cout << "I am going to count to 10.\n"
          "Press ENTER at any time to stop.\n";

  for (unsigned counter = 1; counter <= 10; counter++)
    {
    cout << "\r   \r" << counter << " " << flush;

    // Wait for one second on the standard input.
    // If standard input is waiting, we're done.
    if (WaitForSingleObject( hStdIn, 1000 ) == WAIT_OBJECT_0)
      {
      cout << "\r   \r> ";
      getline( cin, s );
      break;
      }
    }

  if (!s.empty())
    {
    cout << "(You entered \"" << s << "\".)\n";
    }

  cout << "OK. All done.\n";

  return 0;
  }

Try running it and letting the time run out.
Try running it and pressing ENTER.
Try running it and entering a string.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

What you want to do is not something that is addressed by the C or C++ standards: you must use OS-specific code or special extensions.

On Windows (which you are using if you are using Dev-C++), you should use the WaitForSingleObject() function. Use GetStdHandle() to get the first argument. You'll need to #include <windows.h> .

On *nix systems you would want to use select() or poll() function.

Either way, you have the option of specifying a limited timeout. The timeout will always let you know whether the function returned because there is input waiting or the time just ran out, so you can choose how to continue based upon that.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You need to either run your program from the command prompt, or put some form of pause at the end of your program.

For example:

#include <iostream>
#include <limits>
using namespace std;

int main()
  {
  // This is my program
  cout << "Hello world!\n\n\n";

  // This keeps the console window open on Windows.
  cout << "Press ENTER to quit." << flush;
  cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

  return 0;
  }

Personally, I recommend you get used to using the command prompt when working with console programs. On Windows, you can get to the command prompt by clicking Start, Run..., and typing "cmd". Then use the "cd" command to change to the directory where you compiled your program. Then type the name of your program and see it go.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Hmm, just a good habit I've gotten into. (You just never know when a copy of your object will be used when a reference would have done.)

Stay away from always/never rules. The "Rule of Three" isn't always the right thing to do. In any case, I meant to keep the examples as simple as possible.

Duoas 1,025 Postaholic Featured Poster

You need to specify the standard you are compiling against. The GCC defaults to using its own extensions. g++ -Wall -ansi -pedantic ... Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The BitBlt() function doesn't resize images. You need StretchBlt().

It does a really bad job, btw, so it might be worth your while to use an external library to do image transformations.

Hope this helps.