Adding more to a string?

This is a discussion on Adding more to a string? within the C++ Programming forums, part of the General Programming Boards category; Hi Say you have to strings, "final" and "input". You use cin.getline to get the value of input. You want ...

  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, 10:03 PM
  2. Replies: 4
    Last Post: 03-03-2006, 01: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, 01:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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