string name for a file

This is a discussion on string name for a file within the C++ Programming forums, part of the General Programming Boards category; Hey guys I need some major help. I am trying to find a way to do this: Code: #include <iostream.h> ...

  1. #1
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42

    string name for a file

    Hey guys I need some major help. I am trying to find a way to do this:
    Code:
    #include <iostream.h>
    #include <string>
    #include <fstream.h>
    using namespace std;
    
    int main()
    {
    
     string name = "whatever";
     ofstream goingOut("C:\\windows\\desktop\\"name".txt");
     goingOut<<"Hello I need some help!"<<endl;
    
     return 0;
    
    }
    I can't seem to compile this. Could you guys tell me what I am doing wrong?

    Thanks,
    Machewy
    "All things come to an end"

  2. #2
    Iamregistered
    Guest
    any errors?

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571

    Re: string name for a file

    1. Mixing deprecated and new standard headers is not a good idea. If your compiler supports the correct headers, you should use them; if your compiler is too old to support the standard headers, it's time to look at new compilers.

    2:
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;
    
    int main()
    {
    
     string name = "whatever";
     string fullName = string("C:\\windows\\desktop\\") + name + ".txt";
     ofstream goingOut(fullName.c_str());
     goingOut<<"Hello I need some help!"<<endl;
    
     return 0;
    
    }
    Last edited by Cat; 06-14-2003 at 10:12 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Replies: 6
    Last Post: 01-03-2007, 02:02 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

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