Link to home
Start Free TrialLog in
Avatar of List244
List244

asked on

Order Correction

#include <iostream.h>
#include <conio.h>

void CPost();

int main()
{
   CPost();
   getch();
   return 0;
}

void CPost()
{
   cout<< "Hello\n";
}

I have the following code. I have put CPost to its
own function in attempt to answer my own
question, it did not work, but I post it this way
anyway. My question is how do I force it to
Cout then GetCH. Currently it does GetCH then
Cout, which ... messes things up, and prevents
me from continuing on.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SirHando
SirHando

Use cin to read the characters.

cout & cin are tied together, so that things will work in order.

If you mix c-library methods with c++ streams, there there is guarantee on the order.

Ciao

SirHando
It works as:

This deals with the namespace problem pointed out by jaimie for the cout and changes your getch to getChar() from the C standard library


 #include <iostream>
 #include <stdio.h>

void CPost();

int main()
{
   CPost();
   getchar();
   return 0;
}

void CPost()
{
   std::cout<< "Hello\n";
}
sorry getchar() not getChar()
Avatar of List244

ASKER

I know I can use Cin but, I wanted to avoid that.
However, adding the namespace worked out
great, thanks jaime.
twobitadder,

> #include <iostream>
> #include <stdio.h>

With <iostream> you should really use:

#include <cstdio>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial