Pass a string vector index as parameter

Hi!
I have tried to pass an index of a string vector as parameter and haven't found anything on the internet useful.
I am trying to implement a DFA and I want to access a string at a specific index.
Thx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vector <string>lines
void AFD::start(int i, vector <string>lines.at(i)) {	
	for (string &str : lines) {
		for (char &ch : str) {
			it = std::find(lines.begin(), lines.end(), "a");
			if (it != lines.end()) {
				dfa = 1;
			}
			else {
				dfa = -1;
			}
			
		}
	}
void AFD::start(int i, vector <string>lines.at(i)) {
This makes no sense. What do you want to pass to this function? An int and a string?


Here is how to create a function that takes an int and a string:
void AFD::start(int i, string some_string) {



Or do you want to create a function that accepts an int and a vector<string> ?
void AFD::start(int i, vector<string> a_vector_of_string) {
Last edited on
I want the function to access a specific index of the string vector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <vector>

void AFD(std::vector<std::string>&, unsigned);

int main()
{
   std::vector<std::string> lines { "Hello", "World", "Good-Bye", "Word", "Test", "Dictionary" };

   AFD(lines, 2);
}


void AFD(std::vector<std::string>& lines, unsigned pos)
{
   std::cout << "The string at index " << pos << " is: ";

   std::cout << lines.at(pos) << '\n';
}

The string at index 2 is: Good-Bye

How you adapt the above example to your code is up to you.
Thx:)
Topic archived. No new replies allowed.