Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String concatenation 1

Status
Not open for further replies.

DerPflug

Programmer
Joined
Mar 28, 2002
Messages
153
Location
US
How can I concatenate the following into a character string in the format "July 20, 2000" using the following variables?

Code:
int D,Y;
char *month = new char[10];

'month' would equal "July", 'D' would equal 20, and 'Y' would equal 2000. Do I need to convert the int's to strings as well?

Thanks.
 
Code:
	char* month = "July";
	int D = 20;
	int Y = 2000;

	char datebuf[50];
	sprintf( datebuf, "%s %d, %d", month, D, Y);

-pete
 
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{

char *pszMonth = &quot;October&quot;;
int iDay = 21;
int iYear = 1969;
stringstream ss;

ss << iDay << &quot; &quot; << pszMonth<< &quot; &quot; << iYear;

cout<<ss.str()<<endl;

return 0;
}

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top