Without using stringstream you would need to write your own function that transcribes each integer into its corresponding char value. sstream is faster than writing a function to transform large numbers but of course it has its own problems.
You could try boost::lexical_cast, but I recommend sstream.
intconst NUM = 1000;
//the length is 12 because of the the maximum number of int + sign + '\0'
//this could be different at different platforms or compiler
char intToStr[12];
sprintf(intToStr, "%i", NUM);
cout<<"intToStr = "<<intToStr<<"\n";
this way is faster but less flexible and unsafe
choose the solutions you need according to your application
I don't know if I should make a new thread or not but I made my program with stringstream and now I have a string array of 30 IPv4 addresses.
My question is: How can I sort my string array of numeric IP addresses in ascending order? I only know bubble sort to sort integer arrays and I haven't learned how to use <algorithm> yet.
you could implement the algorithm by yourself, this could be a good practice
besides bubble sort, there are selection sort, quick sort, heap sort, merge sort and other's
I print out the first and last 3 items of my array after sorting and it only sorts up to 99. I know there are strings that begin with 255... but it doesn't seem know those are larger than 99.
Okay, I am really struggling with this, here is my source code, but when I sort it thinks 0 is the lowest and 9 is highest, but 255 should be higher than 99. I have been trying really hard to use everyone's suggestions, but I am stumped: my C++ knowledge is very limited.
I want to try it your way, Duoas, but I can't figure out how to concatenate 4 random shorts without turning them into strings first.
EDIT: I just realized that I can make 4 arrays then concatenate them after I've sorted them and add periods!! I feel like an idiot. I was thinking too much into this. I truly appreciate all your help.
what is a struct? is that a data type like void or main?
I wish I could understand that but I'm not at that level yet. This is what I have so far and you're correct.. my output is not what I want because there are a lot of repeats due to the way I am sorting I think?