which function needed for getting a sub string ?

which function needed for getting a sub string ?

and which should i include #include<XXXX>

e.g. str1 = "i am happy now", how to get sub string "happy"?
thanks
Last edited on
besides, i want to ask how to truncate a double at specific digit?

hap= 6.3496

hap2 = trunc (hap, 2);

hap--> 6.34

it's pascal , hopw about C++

and also how to round ?
Last edited on
To truncate you can use some tricks:
1
2
3
double d = 1.2345;
int i = d*100;// here truncates to 123, you can use d*pow(10,n) where 'n' is the number of decimal digits you want
d = i/100.0;// convert back to double -NOTICE: doubles are not precise so you can't have a precise truncation- 


For some rounding algorithms read this article: http://www.cplusplus.com/forum/articles/3638/
d = 1.2345;
tmp = pow(10,digit) ;

d *= tmp ; // d = 123.45

d = floor( d) ; d= 123

d /= tmp ; convert back to double

d = 1.23
Topic archived. No new replies allowed.