S
Stefano Sabatini
Hi guys,
which is the best way to define a std::string using some C strings
(arrays of chars)?
Here it is the code:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
// this won't even compile, since in this case "this is a" and
// others string are interpreted like char arrays
// s = "this is a" + " string.";
// OK, but awkward
s = string("this is a") + string(" string.");
cout << s;
// a better way??
// s = ...
return 0;
}
which is the best way to define a std::string using some C strings
(arrays of chars)?
Here it is the code:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
// this won't even compile, since in this case "this is a" and
// others string are interpreted like char arrays
// s = "this is a" + " string.";
// OK, but awkward
s = string("this is a") + string(" string.");
cout << s;
// a better way??
// s = ...
return 0;
}