Whenever I try to run a compiled group of code that should bring up a console, the console just flases onto the screen and is gone...I've copied a few programs from this forum onto it to check and see if its just me but it does it every time.

hi,

you have to make your programs to wait for KeyPress or if you write in windows os then send system("PAUSE"); message.

the other solution is to run all your program from command prompt (cmd.exe)

here is some example code:

#include <iostream>

using namespace std;

int main() {

     char* name;
     cout << "Enter your name, please: " << endl;
     cin >> name;
     cout << "Your name is: " << cin << endl;

     system("PAUSE");
     return 0;

}

you can use cin.get(); instead of system("PAUSE");

thats all :P

i hope this will help you.

Much thanks. This must be one of the other changes between the text book I used last year and now.

EDIT: Lol I got a critical error running it after entering my name guess it dosnt' like me still :rolleyes:

Hi,

excuse me it's all my fall, i was hurry during writing this post because my boss was looking around my desk .. hehehe

so the problem line is:

cout << "Your name is: " << cin << endl;

it should be name instead of cin.

and here is another one example but this time we get the whole line:

#include <iostream>

using namespace std;

int main() {

	char myName[256];

	cout << "Enter your name, please: " << endl;
    cin.getline(myName, 256);
    cout << "Your name is: " << myName << endl;

    system("PAUSE");
    return 0;

}

:P

Ah yes I picked up on it right after I posted, however it still crashes the first block of code. The second runs fine.

Whats with the namespace std thing? Rather, what is std mean in C++?

Also, why did you use an array for variable MyName

hi,

my english isn't perfect but i'll try to explain you:

using namespace std; telling to your compiler that we will using functions who belong to name space std and then you can use all function who belong to this name space wihtout to telling that to your compiler each time you using them.

for example i'll write you the same program but without defini the name space:

#include <iostream>

int main() {

	char myName[256];

	std::cout << "Enter your name, please: " << std::endl;
	std::cin.getline(myName, 256);
	std::cout << "Your name is: " << myName << std::endl;

    system("PAUSE");
    return 0;

}

i hope you will understand what i'm trying to explain you :)

and for the array i prefer to use arrays for more reasons.
it this example i using it to tell my program that name longer that 256 chars is not allowed and the program will display only 256 chars.

that's it ... if you want you can change array size to 5 and to try enter more that 5 chars :)

that is half c, half c++. If you want a code in C++, it would look like this:

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

int main( void ) {
  string name;
  char buff[257];
  cout << "Your name: ";
  cin.getline( buff, 257 );
  name = buff;
  cout << "Your name is " << name << endl;
  system( "PAUSE" );
}

If you want to get see what is written, you can always use the cmd. If you know to use DOS, using cmd wont be difficult for you.

I would suggest you to use the function getch(); in the header file conio.h .

If you do not have the conio.h file you can downoad Visual C++ Express or use the bsic Turbo C++ 3.0.

I use the Turbo C++ 3.0(dont judge it by graphics) as its easier to use.

commented: Wow! Such a fast reply, after three years!!! Man you're fast! -1
commented: This thread is almost as old as Turbo... -4

>I use the Turbo C++ 3.0(dont judge it by graphics) as its easier to use.
Then your outdated suggestions are likely to be useless to the majority of people here. C++ has grown since then, and most modern compilers will simply refuse to compile your code.

Do yourself a favour: don't use system("pause"); Use cin.get ();

commented: This post should have been the immediate answer to post#2 +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.