std::string sInput = "http://www.cplusplus.com/forum/post.cgi?w=new&i=854";
vector<std::string> sStr;
vector<std::string>::iterator Str_t;
int c = 0;
size_t found;
std::string sTxt = "";
found = noteText.find_first_of("/");
while (found!=string::npos)
{
sTxt = sInput.substr(c,found);
sStr.push_back(sTxt);
std::string Temp = sInput.substr(found+2);
sInput = Temp;
found=Temp.find_first_of("/");
}
In above code I want to retreive text between "/" & strore it in vactor.It is working fine till retreiving correct values but when it inserts string using sStr.push_back(sTxt);in vector shows <bad ptr> at location 1.After completing I tried to print the values in vector using -
1 2 3 4
for (int i = 0;i<sStr.size();i++)
{
printf("%s\n",sStr[i]);
}
It writes <NULL> .
Please let me knwo what I am missing?
Firstly when printf says that with a %s parameter it can print a string, it really means a c-string (it's a c function) which is a const char*. With std::string either cout << str or printf(..., str.c_str())