Hello all,

I'm used to java programming and php. I'm trying to learn C++, but it's rather difficult for me.

Basic in java:

String message = "Test";
String temp = "This is a " + message;

temp now contains "This is a Test".


In c++ i tried everything, a + a dot (in php) etc.
Nothing seems to work.
I tried to search google but no results.

What i do know is i can use cout:

cout << "hello " << "world" << somevariable;

but i want to store my variable not to print it.

Thanks!

Oritm
Deleted Member

Its done almost like you posted it. Post what you have tried so that we can see what you might be doing wrong. You have to include <string>, and its lower-case "string", not "String". C++ is case sensitive, so you have to be careful about using capital letters.

Edited 7 Years Ago by Ancient Dragon: n/a

In c++ i tried everything, a + a dot (in php) etc.
Nothing seems to work.

#include<string>

:)

Ciao,
Angelo

Edited 7 Years Ago by Bezelis: n/a

I also included time.h and string.

string Clogger::getTimeStamp()
{

	char dateStr [9];
	char timeStr [9];

	_strdate_s( dateStr);
	_strtime_s( timeStr );
	
	return dateStr + timeStr;
}

This doesnt work.. it's complaining about pointers..

edit: forgot the formatting

Edited 7 Years Ago by Oritm: n/a

In C++ there are multiple varieties of strings. C style strings are null terminated char arrays. dateStr and timeStr in post #4 are probably going to be used as null terminated char arrays. Null terminated char arrays cannot be concatenated using the + sign. They must be concatenated using strcat(), or similar function, which I believe is in the header file called cstring, or string.h if you have an outdated compiler. cstring also has other functions that can manipulate C style strings. The standard string class declared and defined by the header file called string is part of the Standard Template Library. STL string objects are not nulll terminated char arrays. They can be concatenated using the + operator.

Edited 7 Years Ago by Lerner: n/a

This question has already been answered. Start a new discussion instead.