Convert a string from Java to C++ -


i have string in java:

string op="text1 "+z+" text2"+j+" text3"+i+" "+arrays.tostring(vol); 

where "z", "j" , "i" int variables; "tostring()" function belongs class.

class nod {     private:         char *op;     public:         char nod::tostring()         {         return *op;         } } 

and "vol" vector of int variables.

and want convert c++.

can me please?

edit:

sorry because confuse you, "tostring()" not function belongs class.

"arrays.tostring()" - class java.

to append int string, can use std::stringstream :

#include <sstream> #include <string>  std::stringstream oss;  oss << "text1 " << z << " text2" << j << " text3" << i;  std::string str = oss.str(); 

the method str() returns string copy of content of stream.

edit :

if have std::vector, can :

#include <vector>  std::vector<int> arr(3); unsigned int size = arr.size(); ( unsigned int = 0; < size; i++ )     oss << arr[i]; 

or there c++11 way thing :

#include <string> #include <vector>  std::vector<int> arr(3);  std::string result = "text1 " + std::to_string(z); result += " text2" + std::to_string(j); result += " text3" + std::to_string(i) + " ";  ( auto& el : arr )     result += std::to_string(el); 

you can take @ std::to_string.

here live example of code.

remember not compilers support c++11 of right now.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo