Which C++ string function returns nth character of the string?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 3
Reputation: deactivated is an unknown quantity at this point 
Solved Threads: 0
deactivated deactivated is offline Offline
Newbie Poster

Which C++ string function returns nth character of the string?

 
0
  #1
Mar 28th, 2008
This has been driving me nuts for the last half hour or so. Google didn't help. I don't know which function returns the nth character in the string. I know that it is supposed to be something like this

stringname.something(n?)

If someone could post the function and an example of how to use it, I would really appreciate it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: pralu is an unknown quantity at this point 
Solved Threads: 0
pralu pralu is offline Offline
Newbie Poster

Re: Which C++ string function returns nth character of the string?

 
-1
  #2
Mar 28th, 2008
there is no string data type in c++... the string u enter is in char array.... so u already have the access to any index element in the c++ string
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: Which C++ string function returns nth character of the string?

 
0
  #3
Mar 29th, 2008
If you are using char[] array or STL strings, just use the [] operator. e.g.
  1. #include <string>
  2. using namespace std;
  3. ...
  4. string mystring = "hello";
  5. v = mystring[n]; // v = nth character of string
  6.  
  7. // or
  8. char mycharstring = "hello";
  9. v = mycharstring[n]; // v = nth character of string
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Which C++ string function returns nth character of the string?

 
0
  #4
Mar 29th, 2008
Or you could use std::string's at() method, but I don't see that very often. Read this about it.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC