adding strings?

This is a discussion on adding strings? within the C++ Programming forums, part of the General Programming Boards category; is there a way of adding a phrase to a string together to make one? i already know you can ...

  1. #1
    Registered User Led4urhead123's Avatar
    Join Date
    Jul 2008
    Posts
    3

    adding strings?

    is there a way of adding a phrase to a string together to make one?
    i already know you can add two strings togethor.

    sort of like this

    Code:
    cout<<"Path: "; cin>>filename;
                  
                  string dir = "dir " + filename;
    Last edited by Led4urhead123; 07-10-2008 at 02:58 PM.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,740
    If inserting strings or characters to the front or back is not sufficient, you can always use one of the insert member functions, like this version which uses iterators:
    Code:
    #include <iostream>
    #include <string>
    
    int main ()
    {
        std::string part[] = {"mystuff", "/path/to/"};
    
        part[0].insert(part[0].begin() + 2, part[1].begin(), part[1].end());
    
        std::cout<<part[0]<<'\n';
    }
    Choose a function which you can understand and will do the job you need to do.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Are you having a problem? If filename is a string then the posted code should compile fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding Strings to ListBox in a Dialog
    By kevins963 in forum C Programming
    Replies: 5
    Last Post: 09-10-2008, 04:36 PM
  2. adding strings hard problem...
    By qubit67 in forum C Programming
    Replies: 28
    Last Post: 04-22-2007, 02:02 AM
  3. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  4. Adding two strings to make a wchar_t
    By ElWhapo in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2005, 10:36 PM
  5. adding onto strings
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 09-11-2002, 01:06 PM

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