the original value is an int converted to a string so I was expecting a string element that is 11 and at index 0, as opposed to it being split into 1 char at index 0 and another char at index 1
A string is just a fancy array of chars. A string isn’t an actual type. It’s a class. Do you know what an array is and do you know what a class is.
Edit: also, if you insert a space into a stream, it’s inserted into the stream. Period. It doesn’t just disappear, there are some things that don’t show up, like some escape characters. (Ever heard of the bell character? That doesn’t show up when you cout it, it makes a sound.)
shouldn't it be 11 despite the space I have in between in cout " "?
You are treating the std::string as a C-style string. Your range-based for loop is printing out individual characters, each array element in the string, with the loop iterations. The output you are getting is correct.
11 is 2 chars as a string (3 in C style). you can't fit it into 1 char. If you just want to print it, cout already knows what to do with int. just cout <<intvar << " " and you have an int followed by a space, if that is what you want. Char is not a string, its a single letter and in reality its a signed byte, nothing more.
clearer now. Thanks againtry. I've just been "staring" at the same area of code for several days for a coding challenge. Most of my program works and I have the results in a vector of int's that are the prime factors of a given number. I just need to count the duplicates in order output the results to a string. Hence, I've been playing around with converting ints to strings, etc. I got confused with the size of types, strings, char... anyhow, I think the option might be to use std:map containers to count out the duplicates easily.
nope, look above at his comments SJW....superiority complex is developed from a defensive need to overcome "inferiority" in the first place...in case you didn't know.
I apologize if what I said was in any way offensive, I simply have no idea of you skill level. It was an actual question. It just seemed a kinda strange statement to say that a single index of a string would hold another string. I apologize.