Thread: Adding more to a string?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    Adding more to a string?

    Hi

    Say you have to strings, "final" and "input". You use cin.getline to get the value of input. You want final to be like: "./pics/" input ".bmp" but how do you add the input string in the middle of final??

    Thanks.
    ...

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    You can use the c runtime string functions such as below:

    Code:
    #include "stdafx.h"
    #include <stdlib.h>
    #include <iostream>
    using namespace std;
    
    
    int main() 
    {
    	char szFinal[ _MAX_PATH ] = { '.', '/', 'p','i','c','s','/' };	
    	char szInput[ _MAX_PATH ] = { 0 };
    
    	cout << "Enter a something: ";
    	cin.getline( szInput, 80 );
    
    	strcat( szFinal, szInput );
    	strcat( szFinal, ".bmp" );
    
    	cout << szFinal << endl;
    
    	return 0;
    } // end

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Adding elements to a string
    By Vicked in forum C Programming
    Replies: 2
    Last Post: 04-10-2003, 12:52 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM