P
Pradeep
Hi All,
I am facing an issue where length method of std::string class gives a
junk value when used in a expression.
Here's an example. The code should not go into the for loop but it
does because the value of j-str.length comes out to be some junk value
int j = 12;
std::string
str("0123456789012"); //
of length 13
std::cout << "str length" << str.length() <<
std::endl; // gives 13
std::cout << " j - str.length" << (j- (str.length())) <<
std::endl; // gives junk value
for(int i=0; i < j - str.length() ;i+
+) // so it goes
inside the loop
//
while it should not for 12-13
//
= -1
{
std::cout << "Show hte problem" << std::endl;
}
However it starts to work if instead of the expresssion I use a
variable
int x = j - str.length.
Can somebody help me out and tell me the reason for this.
Thanks in advance,
Pradeep
I am facing an issue where length method of std::string class gives a
junk value when used in a expression.
Here's an example. The code should not go into the for loop but it
does because the value of j-str.length comes out to be some junk value
int j = 12;
std::string
str("0123456789012"); //
of length 13
std::cout << "str length" << str.length() <<
std::endl; // gives 13
std::cout << " j - str.length" << (j- (str.length())) <<
std::endl; // gives junk value
for(int i=0; i < j - str.length() ;i+
+) // so it goes
inside the loop
//
while it should not for 12-13
//
= -1
{
std::cout << "Show hte problem" << std::endl;
}
However it starts to work if instead of the expresssion I use a
variable
int x = j - str.length.
Can somebody help me out and tell me the reason for this.
Thanks in advance,
Pradeep