-
cout<<"Hello "<<name;
for some odd reason Borland 5.0 compiler dosnt like the following code.
#include <iostream.h>
int main()
{
char name[25];
cout<<"Please type in your name\n";
cin<<name;
cout<<"Your name is: "<<name;
return 0;
}
i get no errors but when i run it winblow$ comes up with a critical error any clues what is happening???
-
cin<<name; should be cin>>name;
-
woops my bad thats just a typo when i wrote it out. In the real program its fixed
-
try adding a null character to the end of the string.
-
try this
Code:
#include <iostream.h>
int main()
{
char name[25]={0};
cout<<"Please type in your name\n";
cin>>name;
cout<<"Your name is: "<<name<<flush;
return 0;
}
if that doesn't work then try this...
Code:
#include <iostream.h>
int main()
{
char name[25]={0};
cout<<"Please type in your name\n";
cin.getline(name,sizeof(name));
cout<<"Your name is: "<<name<<flush;
return 0;
}
-
Dont blame the OS for errors in your simple code.
-
Or, do it the c++ way:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string name;
cout <<"Enter you name:"<<endl;
cin >> name;
cout <<"Your name is "<<name;
return 0;
}
-
Right on, Hannwaas!!! C++ way is a LOT easier.