I was trying to pass myStringArray
to a function in the following code.
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
int loopy(auto someString){
for (auto Word : someString){
cout << "In " << __func__ << " word is " << Word << endl;
}
return 0;
}
int main(){
string myStringArray[] = {"abc","def", "xyz", "meh" };
for (auto Word: myStringArray){
cout << "In " << __func__ << " word is " << Word << endl;
}
loopy(*myStringArray);
return 0;
}
The o/p I see is:
$ ./a.out
In main word is abc
In main word is def
In main word is xyz
In main word is meh
In loopy word is a // <<-- this
In loopy word is b // <<--this
In loopy word is c // <<--this
As you can see, the loopy
function only does see the 1st word of the string array(?) that I am passing.
What am I doing wrong, and what's the correct way to pass these C++ nuances to functions? Thanks!