I am very new at coding and I just had a quick question.
How would you find the nth character from a string in an array for c++?
so for example
{"Hey you" "echo" "lake" "lend" "degree"}
, n=0
would equal "hello"
thanks! I'm not going to ask for the full code but just tips on where to get started.
Asked
Active
Viewed 1,132 times
-3
-
2Show what you have tried and ask specific questions on where you are stuck. We will not write the code for you. – Anon Mail Oct 06 '17 at 20:39
-
Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Oct 06 '17 at 20:39
-
1. Hello doesnt appear in your example array. 2. This is a question answer site, not a get started in the right direction site. 3. Did you do any pre-work, try searching google for this. – Fantastic Mr Fox Oct 06 '17 at 20:39
-
Please provide context for your question. How is your array defined? Do you know the difference between "character", "string" and "array"? Try to make a [mcve]. – Yunnosch Oct 06 '17 at 20:40
-
_"on where to get started"_ at the 1st character of course. – user0042 Oct 06 '17 at 20:40
-
1Please have a look at this [C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) list. – Ron Oct 06 '17 at 20:51
1 Answers
1
Here are some examples:
unsigned int n = 3;
static const char hello[] = "hello";
cout << hello[n] << "\n";
const std::string apple = "apple";
cout << apple[n] << "\n";
static const char * many[] = {"These", "are", "many", "strings"};
cout << many[n][n] << "\n";
cout << many[n] << "\n";

Thomas Matthews
- 56,849
- 17
- 98
- 154