txtfile title=char and concatenating=string, must convert string to char =( need help

This is a discussion on txtfile title=char and concatenating=string, must convert string to char =( need help within the C++ Programming forums, part of the General Programming Boards category; well first of all, I'm using windows and new compiler(Bloodshed DevCpp YAY ) well here's my situation i cant really ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    19

    txtfile title=char and concatenating=string, must convert string to char =( need help

    well first of all, I'm using windows and new compiler(Bloodshed DevCpp YAY )

    well here's my situation i cant really continue unless there's a solution...

    The problem is under function void make_file. I tried using the loop thing and lib string isn't really helping(or i just didnt know the potential of it) anyways i hope someone can help me. i cant make the file name unless its char, and i placed the supposed to be file name in struct name.data[1] and its a string(why string cuz i concatenated it). and converting it to char is probably my first prob. Mind that my problem is only focused on function void make_file. others works fine. but suggestion swill be accepted, if your wondering what the hell i;m doing... just imagine cut file from one directory like "c:\" to "d:\" with file creating, deleting files and extras

    Thanks in advance

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    // string data 1 is from/old and data 2 is to/new kk?
    struct info{string data[2];}location,name,msg;
    
    void create();
    void open();
    void del();
    void make_file();
    
    
    int main()
    {
        int select = 0;
        while(select<1||select>4)
        {
            system("cls");
            cout<<"Select File Option: \n";
            cout<<"[1] - Create File \n";
            cout<<"[2] - Open File \n";
            cout<<"[3] - Delete File \n";
            cout<<"[4] - Exit \n";
            cout<<"Execute: ";
            cin>>select;
            switch(select)
            {
                case 1: create();
                        break;
                case 2: open();
                        break;
                case 3: del();
                        break;
                case 4: system("cls");
                        cout<<"Thank you... \n";
                        cin.get();
                        break;
                default: 
                        cout<<"Please Enter Correctly";
                        system("pause");
                        break;
            }
        }
        system("pause");
        return 0;
    }
    
    void create()
    {
        string filename;
        system("cls");
        cout<<"Create File: \n\n";
        cout<<"LocatioN: ";
        cin>>location.data[1];
        cout<<"\nFilename: ";
        cin>>filename;
    //concat found here 
        filename += ".txt";
        name.data[1] = filename;
        cout<<"\nMessage: ";
        cin>>msg.data[1];
        
        make_file();
        
    }
    
    void open()
    {
        system("cls");
        
    }
    
    void del()
    {
        system("cls");
    }
    
    // here's the problem...
    void make_file()
    {
        char we[50];
        we=name.data[1];
        cout<<we;
    }
    Last edited by jazzglenn421; 09-12-2010 at 02:13 AM.

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    30
    you mean, you use the std string library for concatenation, but you need the file name stored as a character array for opening the file, is it?
    If so, then you could use the "c_str" function from std string library, it returns a char array representation of the string.
    say, "filename.c_str()" will get you the char array rep for the string stored in "filename".

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Quote Originally Posted by chameleons View Post
    you mean, you use the std string library for concatenation, but you need the file name stored as a character array for opening the file, is it?
    If so, then you could use the "c_str" function from std string library, it returns a char array representation of the string.
    say, "filename.c_str()" will get you the char array rep for the string stored in "filename".
    Man cant thank you enough... you have just saved me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The UNIX System Interface
    By rrc55 in forum C Programming
    Replies: 1
    Last Post: 10-20-2009, 05:56 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM

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