| | |
Which C++ string function returns nth character of the string?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 3
Reputation:
Solved Threads: 0
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.
stringname.something(n?)
If someone could post the function and an example of how to use it, I would really appreciate it.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
If you are using char[] array or STL strings, just use the [] operator. e.g.
C++ Syntax (Toggle Plain Text)
#include <string> using namespace std; ... string mystring = "hello"; v = mystring[n]; // v = nth character of string // or char mycharstring = "hello"; v = mycharstring[n]; // v = nth character of string
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.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Menu Problem
- Next Thread: I Have One Error Could Someone Please Help Me?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






