Link.
Actually, I didn't know myself string had this method. I have always used += for appending.
Code:std::string numericString;
for(int i = 0; i < 5; i++){
numericString += '1';
}
Printable View
Link.
Actually, I didn't know myself string had this method. I have always used += for appending.
Code:std::string numericString;
for(int i = 0; i < 5; i++){
numericString += '1';
}
What do you mean? I merely provided an example of how to use an index based for loop to iterate over the characters of a string. You would need to combine this with std::string's push_back(), or whatever method you wish to use to append to the destination string.Quote:
Originally Posted by Masterx
You would not need to fully qualify std::string::size_type, so you could write it as string::size_type. std::string::size_type is the index type of std::string.Quote:
Originally Posted by Masterx
soorry to bother , thanks alot Dears. it went all fine , but i got some problem , i cant use "atoi() with string ! what should i do now ?atol() ? does it make it?
Code:for (string::size_type i = found, len = str.length(); i != len; ++i)
{
currentcharacter = str[i];
if ( (isspace(currentcharacter) ))
{
continue;
}
str1+= str[i];
You actually "solved" this problem in your original code by using the c_str() member function of std::string.Quote:
Originally Posted by Masterx
by the way , how could you guys understand that ptr was not allocated ! ? by experience or just its the knowledge of C++ that i can find in books/.?
Stringstreams.
Code:string s("12345");
int n;
stringstream ss(s);
ss >> n;