I have posted the code I am working on below. Right now everything is working except for the printing function called 'onetile'. I am trying to pass in the input 'in' into the function like I did in the function get_tileset. The way it is right now the input file 'in' is not passing to 'onetile'. Any thoughts?
#include <iostream>
#include <vector>
#include <string>
void onetile(std::istream* in, size_t Tsize) {
std::string row;
size_t i{};
std::vector<std::string> filelines;
while (i < Tsize && getline(*in, row)) {
filelines.push_back(row);
++i;
}
for (constauto& line : filelines)
std::cout << line << '\n';
}
int main()
{
onetile(&std::cin, 3);
}
edit: for the expression in the while() loop i < Tsize must be written first, otherwise you'll enter 4 lines of data but print out only 3 as the 4th call to getline() gets evaluated before reaching if i < Tsize
you need the counter to stop reading from std::cin but if you were reading a file then the counter is not necessary as the program will stop reading the file once its eofbit is set