Trying to output to a directory other than the root of where the program is running

This is a discussion on Trying to output to a directory other than the root of where the program is running within the C++ Programming forums, part of the General Programming Boards category; I'm trying to have the output of a program go to a folder other than the one where the program ...

  1. #1
    Compile Errors = Schwa?!
    Join Date
    Aug 2005
    Location
    Ohio
    Posts
    15

    Trying to output to a directory other than the root of where the program is running

    I'm trying to have the output of a program go to a folder other than the one where the program is running from, but a subfolder of the folder its in.

    Ex)

    Folder1 with program and Folder2
    Folder2 within Folder1 where i want the program to output to.

    currently my syntax is:

    Code:
    FileName = "\\Profiles" += "\\" += NewPlayerName += ".html";
         ofstream Playername( FileName.c_str() );
    I've also tried:

    Code:
     "\Profiles\" += NewPlayerName += ".html";
    In all these attempts I think the compiler (Dev-C++) is misinterpreting the "\"s, not to say this is compiler specefic, I think I just don't know the proper syntax for this sort of command.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Try
    FileName = "/Profiles" + "/" + NewPlayerName + ".html";
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
    FileName = "\\Profiles" += "\\" += NewPlayerName += ".html";
    syntax is wrong. Don't use "+=" operator.

    Code:
    FileName = "\\Profiles\\" + NewPlayerName + ".html";

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Howie17
    I'm trying to have the output of a program go to a folder other than the one where the program is running from, but a subfolder of the folder its in.
    use
    Code:
    FileName = ".\\Profiles\\" + NewPlayerName + ".html";
    puts the file into the subfolder Profiles of the working folder.
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  3. program to calculate the square root
    By saszew in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 12:53 PM
  4. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  5. Opening file in directory of the running program
    By Hankyaku in forum C++ Programming
    Replies: 6
    Last Post: 10-11-2003, 06:41 AM

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