简体   繁体   English

C++ 中的多个输入和输出

[英]Multiple inputs and outputs in C++

I have a code that is written in C++17 takes values x and y as inputs and give some value as output.我有一个用 C++17 编写的代码,将值 x 和 y 作为输入并给出一些值作为输出。 I want to change it to take as many inputs ( x and y values) and give outputs.我想改变它以获取尽可能多的输入(x 和 y 值)并给出输出。 What changes needed to be done in the code代码中需要做哪些改动

what is happening in the code is : with some x and y coordinates it finds the coordinate number.代码中发生的事情是:使用一些 x 和 y 坐标找到坐标编号。

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

    // Test values
      const double  x{ 3700 };  // want to  add multiple entries here
      const double  y{ 11261 };  // want to  add multiple entries here

    // Check cell number
    for (const Tile& tile : tiles) {
        if (const auto [isInTile, cellNumber] = tile.getCellNumber(x, y); isInTile) {
            std::cout << "\nCellnumber: " << cellNumber << "\n:)\n\n\n\n\n\n";

        }
    }


    return 0;
}

I have tried many changes but always end in some error also I am new to c++ my primary language is python.我尝试了很多更改,但总是以一些错误告终,而且我是 C++ 的新手,我的主要语言是 python。

If you want multiple input values, then put x,y into a vector, like you did with tiles:如果您想要多个输入值,则将 x,y 放入一个向量中,就像您对瓷砖所做的那样:

    // Test values
    const std::vector<std::pair<double, double>> test_values = {
        { 3700, 11261 },
        { 2500, 10000 },
        { 1000, 5000 }
    };

    // 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 << "\nCellnumber: " << cellNumber << "\n:)\n\n\n\n\n\n";
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM