Thread: small problem

  1. #1
    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.

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    Instruct.h

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    Intro.h

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    NEWGAME

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    LMAP

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    This is default map

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

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

  9. #9
    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
    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
    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
    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]

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, 04: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