The following is the main body of a code that take test values (x and y) and gives some outputs
int main(void) {
const std::vector<Tile> tiles{ Tile(0),Tile(1),Tile(2),Tile(3) };
const std::vector<std::pair<double, double>>
test_values = {
{ 3542, 9966 },
{ 354, 11261 },
{ 354, 6932 },
{ 2354, 2432 },
{ 4354, 10002 },
{ 7354, 4932 },
{ 6739, 8600 }
};
std::cout << "x\t" << "y" "\n";
for (const Tile& tile : tiles)
{
for (const auto [x, y] : test_values)
{
if (const auto [isInTile, cellNumber] = tile.getCellNumber(x, y); isInTile)
{
std::cout << x << "|\t|" << y << "\t|" << cellNumber << "\n";
}
}
}
return 0;
}
Output :
x y
2354| |2432 |126
7354| |4932 |299
354| |9966 |580
354| |11261 |660
354| |6932 |380
6739| |8600 |517
what I want to do is change in the code so that test values ( x and y ) can be taken directly from the csv file rather than typing them all here.
What I have tried:
std::vector<std::vector<std::string> > CSVReader::getData()
{
std::ifstream file(fileName);
std::vector<std::vector<std::string> > dataList;
std::string line = "";
while (getline(file, line))
{
std::vector<std::string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(delimeter));
dataList.push_back(vec);
}
file.close();
return dataList;
}
int main(void) {
const std::vector<Tile> tiles{ Tile(0),Tile(1),Tile(2),Tile(3) };
const std::vector<std::pair<double, double>>
test_values = {
};
CSVReader reader("test.csv");
std::vector<std::vector<std::string> > dataList = reader.getData();
for (std::vector<std::string> vec : dataList)
{
for (std::string data : vec)
{
std::pair<std::string, std::string> p = ;
std::cout << data << " ";
}
std::cout << std::endl;
}
std::cout << "x\t" << "y" "\n";
for (const Tile& tile : tiles)
{
for (const auto [x, y] : test_values)
{
if (const auto [isInTile, cellNumber] = tile.getCellNumber(x, y); isInTile)
{
std::cout << x << "|\t|" << y << "\t|" << cellNumber << "\n";
}
}
}
return 0;
}
I could not pass the read values from csv file to the test values