Saturday, May 22, 2010

C++ question, please help...?

Is there a str.charAt(number) in C++?





so that:


string a = "this is an example."


a.charAt(3) is equivalent to 's'





if there isn't, can you please tell me the alternative way of doing this in C++? Best with simple examples. Thank you very much.

C++ question, please help...?
Yes - str.at(number)





#include %26lt;string%26gt;


#include %26lt;iostream%26gt;


using namespace std;





void main()


{


string a("this is an example.");


cout %26lt;%26lt; "Char at 3: " %26lt;%26lt; a.at(3);


}





Output:





Char at 3: s





Take a look here for more :





http://www.cplusplus.com/reference/strin...
Reply:http://www.ebay.ph/viItem?ItemId=3301535...
Reply:Use the indexer ..





a[3]
Reply:there aint charat u just have at()


hey here is a small list of string functions:





append() : append a part to nther string


assign(): assigns a partial string


at(): obtains character at specified location


length(): length of string





usage


String s1;


s1="test vaue"


cout%26lt;%26lt;s1.at(3)//count starts from 0





output:


t


--------------------------------------...


all functions would have the same method for calling


String var;


var.funcnme(arglist,....);


--------------------------------------...


checktc help file if u want more data or try rading book by balguruswamy c++


No comments:

Post a Comment