Newbie strings question

This is a discussion on Newbie strings question within the C++ Programming forums, part of the General Programming Boards category; I was wondering how you could combine fixed strings and variables into one variable....

  1. #1
    Unregistered
    Guest

    Question Newbie strings question

    I was wondering how you could combine fixed strings and variables into one variable.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can just string streams to do such a task. Note that this might not work with ancient compilers, but it's standard as of 97.

    Code:
    #include <sstream>
    #include <string>
    #include <iostream>
    #include <cmath>
    
    int main() {
    	float pi = 3.14159265;
    	double e = exp(1);
    	int twentyThree = 23;
    	char charArray[] = "deprecated";
    	char theLetterB = 'b';
    
    	std::ostringstream outStream;
    
    	outStream << pi << " " << e << " " << twentyThree << " " << charArray << " " << theLetterB <<
    	 " more stuff\n";
    
    	std::string allOfEmCombined = outStream.str();
    
    	std::cout << allOfEmCombined;
    
    	return 0;
    }
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Unregistered
    Guest
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. Newbie question about string processing
    By prihod in forum C Programming
    Replies: 6
    Last Post: 04-15-2008, 10:14 PM
  4. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  5. Total Newbie Question
    By Kid A in forum C++ Programming
    Replies: 4
    Last Post: 06-22-2006, 05:36 AM

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