String problem :/.

This is a discussion on String problem :/. within the C++ Programming forums, part of the General Programming Boards category; Ok, I have used character arrays most for most of my code, but now they are becoming a pain. So, ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    String problem :/.

    Ok, I have used character arrays most for most of my code, but now they are becoming a pain. So, I swapped some things around to strings.

    I have one error that I'm lost at. ifstream doesnt like strings! Heres my code:

    Code:
     MAPPATH = MPN + EXT + ".txt";
     clrscr();
    
     cout << MAPPATH;
    
     ifstream file_in(MAPPATH, ios::nocreate);
    Now for some reason, ifstream doesnt like this. I have a book on this, but it doesnt use strings to much, theres nothing about file writing with strings... I'm very, very lost :/
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    use string's c_str() method, which returns a pointer to null-terminated character array.

    fstream file_in(MAPPATH.c_str(), ios::nocreate);

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    IT works! Thank you very much!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,269

    Exclamation eek!

    btw, You'd make a lot of people much happier if you didn't use entirely uppercase for variable names.

    There's a constant called MAXPATH which is way to similiar.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  5. Replies: 4
    Last Post: 03-03-2006, 01:11 AM

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