[Help]2nd small c++ project

Posts 1–15 of 18 · Page 1 of 2
[Help]2nd small c++ project
ok so this is the code i learned form a vc++ book ;

Code:
#include "stdafx.h"
#include <iostream>
using namespace std;

using namespace System;

int main()
{
    int length;
	length = 7;
	cout << "The length is ";
	cout << length;
    return 0;
}
my problem is , it executes just fine but everytime i open it , it closes after like 1 second . does anyone know how to fix that ?
Put system("PAUSE"); before you return..
You can also put
char Whit;
cin >> Whit; before you return
You can either do what whit said, or if your compiler supports it like Visual C++ Express Edition 2008 look for a button that says Start without Debugging
Use the search button. Asked many times.
im not sure if the earlier versions do this, but if its visual studio 2010 professonal (express does it too) then when u make the project, make sure its a win32 application and just make the new project with the default options (dont touch anything). The main function will be _tmain(blah blah blah){ but it works exactly the same. Also call me stupid but whats the using namespace system; for? ive never seen it
Quote Originally Posted by mookamoka3 View Post
im not sure if the earlier versions do this, but if its visual studio 2010 professonal (express does it too) then when u make the project, make sure its a win32 application and just make the new project with the default options (dont touch anything). The main function will be _tmain(blah blah blah){ but it works exactly the same. Also call me stupid but whats the using namespace system; for? ive never seen it
extremely inefficient.

use 2008, it auto pauses before return
cin.get();

before you return execution.
add
Code:
int f;
cin >> f;
return 0;
Quote Originally Posted by jonnyboy9985 View Post
add
Code:
int f;
cin >> f;
return 0;
or just cin.get();
Quote Originally Posted by Auxilium View Post


or just cin.get();
Quote Originally Posted by Astral Witch View Post
cin.get();

before you return execution.
Has already been said.
cin.ignore()

It will ignore 1 key pres, also Drake, instead of using cout<<. Use printf():

int length = 7
printf("The lenght is: %d\n", length); // the printf function will replace the %d with the first decimal argument following
Quote Originally Posted by .::SCHiM::. View Post
cin.ignore()

It will ignore 1 key pres, also Drake, instead of using cout<<. Use printf():

int length = 7
printf("The lenght is: %d\n", length); // the printf function will replace the %d with the first decimal argument following
I suppose next you'll be telling him to use malloc instead of new. Tsk tsk.
Quote Originally Posted by .::SCHiM::. View Post
cin.ignore()

It will ignore 1 key pres, also Drake, instead of using cout<<. Use printf():

int length = 7
printf("The lenght is: %d\n", length); // the printf function will replace the %d with the first decimal argument following
ohai this is C++
Quote Originally Posted by Auxilium View Post


ohai this is C++
Still printf()'s better
right above return 0 put

cin.get();
Posts 1–15 of 18 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Talk with us