Hello
I am making a function that reads a text file stores each line into a string array. My problem is I am getting errors with the function but I do not understand what I am doing wrong or how to fix it?
Can you take a look & see what I need to change? :)
the error is
incompatible types in assignment of `std::string' to `std::string[((unsigned int)((int)pic_count))]'
my program:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
string read(string file, int& counter);
int main() {
int pic_count = 0;
int usedPic_count = 0;
string pic_array[pic_count];
string used_pics[usedPic_count];
pic_array = read("data.txt",pic_count); // error
used_pics = read("usedPictures.txt",usedPic_count); // error
return 0;
}
string read(string file, int& counter) {
string array[999];
ifstream infile;
infile.open(file); // error
if (!infile) {
cout << "Failed to open file";
return 0;
}
while (infile) {
getline(infile,array[counter],'\n');
counter++;
}
return (array); // error
}