Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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) };

    // Test values
    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";

    // Check cell number
    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:

//Parses through csv file line by line and returns the data in vector of vector of strings.

std::vector<std::vector<std::string> > CSVReader::getData()
{
    std::ifstream file(fileName);

    std::vector<std::vector<std::string> > dataList;

    std::string line = "";
    // Iterate through each line and split the content using delimeter
    while (getline(file, line))
    {
        std::vector<std::string> vec;
        boost::algorithm::split(vec, line, boost::is_any_of(delimeter));
        dataList.push_back(vec);
    }
    // Close the File
    file.close();

    return dataList;
}


int main(void) {
    const std::vector<Tile> tiles{ Tile(0),Tile(1),Tile(2),Tile(3) };

    // Test values
    const std::vector<std::pair<double, double>>

        test_values = {




    };

    // Creating an object of CSVWriter
    CSVReader reader("test.csv");

    // Get the data from CSV File
    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";

    // Check cell number
    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
Posted
Updated 5-Mar-20 1:26am
v2

1 solution

The following statement is incomplete.
C++
std::pair<std::string, std::string> p = ;
 
Share this answer
 
Comments
Richard MacCutchan 5-Mar-20 7:47am    
Well it is not clear what you are trying to do at that point, and what the difficulty is.
Richard MacCutchan 5-Mar-20 8:35am    
Yes, you already told us that. But what is the actual difficulty with the code you have?
Richard MacCutchan 5-Mar-20 9:01am    
OK stop, take a step back and think carefully about what you are trying to do. No one here has ever seen this code before so we are relying on you to explain what it should do and why it is not working. It is no good saying things like, "does not work", "it is wrong", etc., because that does not mean anything. So please, explain exactly and clearly what the code is supposed to do and where it is going wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900