small problem

This is a discussion on small problem within the Game Programming forums, part of the General Programming Boards category; This is a realy dum question but why are my Strings and stuff not being used in my intro.h and ...

  1. #1
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Exclamation small problem

    This is a realy dum question but why are my Strings and stuff not being used in my intro.h and other classes? It says theres a parce error but i don't see it.
    Code:
    #include <IOSTREAM>
    #include <string.h>
    String torf,f_name,USER_name,commands,Name; //Says theres parce error before the;
    char User_MAP[20][20],Map[20][20],Get;
    bool newg,end,load;
    using namespace std;
    #include "Intro.h"
    #include "Instruct.h"
    #include "NewGame.h"
    #include "LMAP.h"
    I'll attach the project if anyone wants to look at it.
    It's just a simple text adventure game I havent put everything in yet though.
    Attached Files Attached Files

  2. #2
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    Instruct.h
    Attached Files Attached Files

  3. #3
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    Intro.h
    Attached Files Attached Files

  4. #4
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    NEWGAME
    Attached Files Attached Files

  5. #5
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    LMAP
    Attached Files Attached Files

  6. #6
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    This is default map
    Attached Files Attached Files
    • File Type: txt m1.txt (818 Bytes, 87 views)

  7. #7
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    Instructions. i havent put any instructions in yet though
    Attached Files Attached Files

  8. #8
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    There will be a few more files as well but i havent started them

  9. #9
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    It would have been easier if you put those into a zip file.

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    dont capitalize String. are you trying to use the C++ std string or the C string functions? if youre using the C++ class for string, its <string> not <string.h>. and dont capitalize String like i said earlier.

  11. #11
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    String vs Chars

    How can i compare a string to a character
    like this:

    if (stringa==charb)
    {...}

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    403
    first you must test the string is only one character long using stringa.length(), then just make sure that stringa[0] == charb

    if(stringa.length() == 1 && stringa[0] = charb)

    (i forget atm but stringa.length() may need to be 2, if the above code doesn't work that's probably the case)

  13. #13
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Talking THX...

    THX alot...
    Do you know how to open a i/o file using fstream and a string like this:
    #include <fstream>
    #include <string>
    string stringa='m1.txt';
    ...somecode...
    ofstream filename(stringa,ios::nocreate);
    ...somemorecode...
    Im stumped

  14. #14
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Question

    anyone know
    if(you.control(own.life())==true)
    {...}
    else
    {
    someone.else();
    will()
    }

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Don't bump your threads.

    You answer is to use
    >>ofstream filename(stringa.c_str(),ios::nocreate);
    like in this short example:
    Code:
    #include <iostream>
    #include <fstream>
    int main()
    {
        std::ofstream ofs;
        std::string myfilename = "test.txt";
        
        ofs.open(myfilename.c_str());
        if (ofs)
        {
            std::cout <<"File open successful" <<std::endl;
            ofs.close();
        }
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small Problem with double and integer adding?
    By Nathan the noob in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2009, 04:16 PM
  2. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 10:45 PM
  3. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 03:16 PM
  4. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 04:37 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 03:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21