d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > #include<cstdlib> > Doesnt Work???
Add Reply New Topic New Poll
Member
Posts: 2
Joined: Aug 5 2014
Gold: 0.00
Aug 5 2014 03:27pm
here's some part of the source code... (i didnt post the whole code...)


#include<iostream>
#include<string>
#include<cstdlib>



using namespace std;

int main()

{

string name;
char ans = 0;
char choice = 0;
char namecon = 0;
char exit = 0;
char exit2 = 0;
char diff = 0;
char choice1 = 0;
char choice2 = 0;
char ttmode = 0;

name:cout<<"WHAT'S YOUR NAME?\n";
getline(cin,name);
cout<<"GOOD LUCK AND ENJOY "<<name<<"!!!\n\n\n";
system("PAUSE");
system("CLS");




when i compiled it, it says " [Error] 'system' was not declared in this scope "


what should i do??? i need this program asap. :(

any good suggestions will be appreciated... :)
Member
Posts: 23,261
Joined: Dec 17 2006
Gold: 18,129.00
Aug 5 2014 03:35pm
I don't believe there is a system call in cstdlib. Change it to "stdlib" and that should fix the problem.

Then again, system pauses aren't a great programming habit to get into.
Member
Posts: 14,861
Joined: Jun 28 2007
Gold: 35,165.53
Aug 5 2014 05:15pm
My book I'm learning from hasn't told me about system pause or anything like that (But from googling a lot of people hate this)

Code

#include <iostream>
#include <string>
#include <Windows.h> // to use Sleep

using namespace std;
string name;

void main()
{
cout << "What is your name?" << endl; // Instruct user to input name
getline(cin, name); // get user's input
cout << "Good luck and enjoy " + name + "!!!" << endl; // Message including user's name
Sleep(3000); // Sleep 3000 milliseconds, AKA 3seconds
}
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Member
Posts: 2
Joined: Aug 5 2014
Gold: 0.00
Aug 6 2014 04:57am
thanks for the suggestions!!! i already discovered my problem and made a solution for that. thanks everyone!!! :)
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Aug 6 2014 03:25pm
If you need a sleep or pause in between code segments it is common just to use getchar() or getline() to create a blocking call which will release on keyboard input. Using system() function calls is not a good way to address this.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll