S
sks
Hi,
Here is a small program that is wrtten to simply use substr.
When the second parameter in substr (length of the string to be
extracted) is lesser than 0, the output is the entire string (I'm using
gcc 4.1.0)
My questions are :
1. Is this behaviour correct ? ( Or should this case be an exception?)
2. If it is correct, what is the idea behind this behaviour ?
using namespace std;
#include <iostream>
#include <string>
int main()
{
string s("This is a test string");
cout << s.substr(0,-1) << endl;
return 0;
}
Thanks,
Sumedha Swamy
Here is a small program that is wrtten to simply use substr.
When the second parameter in substr (length of the string to be
extracted) is lesser than 0, the output is the entire string (I'm using
gcc 4.1.0)
My questions are :
1. Is this behaviour correct ? ( Or should this case be an exception?)
2. If it is correct, what is the idea behind this behaviour ?
using namespace std;
#include <iostream>
#include <string>
int main()
{
string s("This is a test string");
cout << s.substr(0,-1) << endl;
return 0;
}
Thanks,
Sumedha Swamy