Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0

    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~
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    i mean like having spaces between the words
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Representin' Quebec
    Posts
    106
    Rep Power
    12
    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!
  6. #4
  7. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    you can do with C syntax like this;

    #include <stdio.h>

    char your_msg[150];

    gets(your_msg);
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    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
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    none of those worked...
  12. #7
  13. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    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;
    }
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    do i need to use char - or will it not work otherwise?
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    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
  18. #10
  19. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    Just saying "help me" is too general. You have to give some description of where you need help.
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    12
    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...
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    --------------------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
  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Representin' Quebec
    Posts
    106
    Rep Power
    12
    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)
  26. #14
  27. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    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.
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0
    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
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo