-
more then one word on a string
once again i am working on my text based game -
when someone on the game has a question i want it to beable to let you type in something - when i use strings it uses one word ( can someone help me so a sentance will work?)
thanks
~Justin~
-
i mean like having spaces between the words
July 10th, 2003, 10:28 AM
-
2 things I can think of right now... first:
char your_array[limit];
cin.getline(your_array, limit-1, '\n');
in cin.getline, the first thing is the destination (an array in this case) second, is the limit, always leave an extra one for the null character, and third is the delimeter. '\n' means newline (enter).
and second could be done using
cin.unset(ios::skipws);
at the beginning. It unsets the 'default' skip white space option in iostream.
I'd be glad to help you with your game. PM me if you want!
July 10th, 2003, 12:25 PM
-
you can do with C syntax like this;
#include <stdio.h>
char your_msg[150];
gets(your_msg);
July 10th, 2003, 03:24 PM
-
for the cin.undet(ios::slipws);
i get this error message:
C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(114) : error C2039: 'unset' : is not a member of 'basic_istream<char,struct std::char_traits<char> >'
I most likey did something wrong
July 10th, 2003, 09:14 PM
-
July 10th, 2003, 11:39 PM
-
the stuff I wrote up top is not complete. Is just showing you what you need. Here's a complete program.
#include <stdio.h>
int main(){
char your_msg[150];
printf("Enter you message: ");
gets(your_msg);
printf("%s\n",your_msg);
return 0;
}
July 11th, 2003, 09:06 PM
-
do i need to use char - or will it not work otherwise?
July 11th, 2003, 09:16 PM
-
omg - if a created a new project and look at it IT WORKS - but if i try it with my game IT DOESN"T Help PLEASE
July 11th, 2003, 09:32 PM
-
Just saying "help me" is too general. You have to give some description of where you need help.
July 11th, 2003, 10:27 PM
-
just do something like this:
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str1;
cout << "Type in a string: ";
getline(cin, str1);
cout << str1;
}
-andy
hmmm...
July 12th, 2003, 10:26 AM
-
--------------------Configuration: Renegadeillusion - Win32 Debug--------------------
Compiling...
Renegadeillusion.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(54) : error C2562: 'main' : 'void' function returning a value
C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(11) : see declaration of 'main'
C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(99) : error C2562: 'main' : 'void' function returning a value
C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(11) : see declaration of 'main'
Error executing cl.exe.
Renegadeillusion.exe - 2 error(s), 0 warning(s)
That is what i get
July 12th, 2003, 11:04 AM
-
Oops! sorry about mine, sumetiemse i typ tou fast! (lol)
it should be "cin.unsetf(ios::skipws);"
Well if you need help because it doesn't work in your game attatch the source code and we'll tell you what you did wrong!
PS: (no offense) but if you didn't about about the stuff we just told you, you should a bit more C++ before you continue your game. You might learn things that make life so much easier such as Structs, Enums and Classes that might help you in the game!
About these: "'void' function returning a value" errors
if you declared a void function it CAN'T return a value. If it was a switch case that returns a value for the string typed in make your function is: int Function(i dunno what you need)
July 12th, 2003, 11:08 AM
-
What's your definition of main? You should opt for one of the following:
void main()
{
// do stuff here
}
or:
int main()
{
// do stuff here
return 0;
}
The former is not standard C++ but a lot of compilers will accept it. You should prefer the latter though.
The latter is standard and in fact the return statement is optional, although some older compilers will complain if you omit it.
July 12th, 2003, 01:07 PM
-
fine heres my code:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
// CopyRight 2003 Shadowillusions
// Justin Shreve
// http://Shadowillusions.com
// Site UnderContruction
string name, lastname, landname, confirmINFO, geteverything, tooksolong;
int age, HP, MP;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your lastname: ";
cin >> lastname;
cout << "Enter your age: ";
cin >> age;
cout << "Enter your landname: ";
cin >> landname;
cout <<name <<" " <<lastname <<" of " <<landname <<"? (Y/N)";
cin >> confirmINFO;
if (confirmINFO =="Y")
{
cout <<endl;
}
else if (confirmINFO =="y")
{
cout <<endl;
}
else if (confirmINFO =="Yes")
{
cout <<endl;
}
else if (confirmINFO =="yes")
{
cout <<endl;
}
else
{
cout <<"Well Okay Then - good bye";
cout <<endl;
return(0);
}
cout <<"The Renegadeillusion \n";
cout <<name <<" was woken up by his mother on a late stormy night...... \n";
cout <<"Mom: It's Stormy badly - the town is going to the shelter near the Magic Gem in the center of the town... \n";
cout <<"Mom: Did you get everything you needed? ";
cin >> geteverything;
cout <<name <<": "<<geteverything;
cout <<endl;
if (geteverything =="yes")
{
cout <<"<Mom: Good Let's Go!";
}
else if (geteverything =="Yes")
{
cout <<"Mom: Good Let's Get Going";
}
else if (geteverything =="no")
{
cout <<"Mom: We Don't have enogh Time to go get it - we will have to leave it";
}
else if (geteverything =="No")
{
cout <<"Mom: We Don't have enogh Time to go get it - we will have to leave it";
}
else
{
cout <<"Mom: What? I didn't understand that.....But We have to get going";
}
cout <<endl;
cout <<name <<" And his Mom run as fast as they could to the gem... \n";
cout <<"Stephine: Thanks god your safe what took you so long? ";
// this is where i want a whole sentance of words to be taken so it can show this:
// eg: cout <<name <" " <<tooksolong
//along with a string or any other way you can get it to work
// I have not used MP or HP yet so if you use Mircrosof Visual c++ you will get these two messages:
// C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(12) : warning C4101: 'HP' : unreferenced local variable
//C:\Program Files\Microsoft Visual Studio\MyProjects\Renegadeillusion\Renegadeillusion.cpp(12) : warning C4101: 'MP' : unreferenced local variable
return(0);
}
Plese help me with this