I want to display numbers in a std::vector<unsigned char>
on a screen, but on its way to the recipient, I need to stuff these numbers into a std::string
.
Whatever I tried (atoi
, reinterpret_cast
, string.c_str()
...), gave me either a nonsense, or a letter representation of those original numbers - i.e. their corresponding ascii characters.
So how do I easily (preferably standard method) convert vector<unsigned char> {1,2,3}
into a string "1-2-3"
?
In the Original Post (later edited) I mentioned, that I could do that in C# or Java.
Upon the request of π?ντα ?ε? to provide example in C# or Java, here is a quick Linq C# way:
public static string GetStringFromListNumData<T>(List<T> lNumData)
{
// if (typeof(T) != typeof(IConvertible)) throw new ArgumentException("Expecting only types that implement IConvertible !");
string myString = "";
lNumData.ForEach(x => myString += x + "-");
return myString.TrimEnd('-');
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…