Passing String array to a function

Ok, so I've done this before but I can't remember how. Ignore all the extraneous code, it will be used later, but I wanted to show everything. I need to pass 3 string arrays to a print function (and it must be done in another function for later use) but you can only return ints out of main so how do I get around that?

Here is my code:

#include<iomanip>
#include<fstream>
#include<iostream>
using namespace std;

#define SIZE 100

string output_function(string, string, string, int i);

class fl_friends{
public:
string first;
string last;
string current;
};


int main(int argc, char**argv)
{

int i; //index variable//
string a_name[SIZE];
string a_var1[SIZE];
string a_var2[SIZE];

fl_friends name, var1, var2;

if(argc != 2){ //Check for arguments//
cout << "Not enough arguments\n";
exit(1); //If none, exit//
}
ifstream fin; //File of information//
fin.open(argv[1]);

i = 0;
while(fin >> name.current >> var1.current >> var2.current){
a_name[i] = name.current;
a_var1[i] = var1.current;
a_var2[i] = var2.current;
i++;
}

output_function(a_name, a_var1, a_var2, i);

return 0;
}

/***********************************************************************
Function
*********************************************************************/

string output_function(string name[SIZE], string var1[SIZE], string var2[SIZE], int i)
{
while(i >= 0)
{
cout << setw(15) << left << name[i]
<< setw(3) << left << var1[i]
<< setw(3) << left << var2[i]
<< endl;
i--;
}
exit(1);
}



The error message is: error: conversion from 'std::string*' to non-scalar type 'std::string' requested

on line 59 (which is the function call)

Last edited on
Your function declaration: string output_function(string, string, string);
doesn't match your function definition: string output_function(string name[SIZE], string var1[SIZE], string var2[SIZE])
You need to #include <string> and your prototype needs to be :
string output_function(string[SIZE], string[SIZE], string[SIZE]);
Wow...... Thanks for that. That's what I get for changing my prototype name 500 times. Thanks again.
Topic archived. No new replies allowed.