Hi, I’m new to c++ and am looking for some help. I’ve searched through most of the site but cant find exactly what I need, so thought I’d ask.
I need to read in strings (arrays of char) from a text file in a function then pass them back to the main. The code below does this but only for 2 strings. How do I go about changing the function to take arrays of strings, in other words 2d arrays of chars?
Thanks
#include <fstream>
#include <iostream>
#include<string.h>
using namespace std;
char get(char [], char[]);
int main()
{
char string1[6];
char string2[6];
get(string1,string2);
//print out 1st string
for(int w =0;w<6;w++)
{
cout<<string1[w];
}
cout<<endl;
//print out 2nd string
for(int e = 0; e<10;e++)
{
cout<<string2[e];
}
int q;
cin>>q;
return 0;
}
char get(char string1[6], char string2[6])
{
ifstream fin("input.txt");
fin >> string1;
fin >> string2;
return 0;
}