C++ C++;使用读入的字符串的数组

C++ C++;使用读入的字符串的数组,c++,C++,我的程序正在读取两个文本文件,一个进入数组,另一个正常启动读取。正在读取到数组中的具有项目代码、价格、数量和项目名称。当商品代码与另一个文本文档上的代码匹配时,我需要获取与之关联的价格,但无法确定如何进行 while (!purchasesFile.eof()) { purchasesFile >> PurchaseItem >> purchaseQty; cout << purchaseNum << " " <<

我的程序正在读取两个文本文件,一个进入数组,另一个正常启动读取。正在读取到数组中的具有项目代码、价格、数量和项目名称。当商品代码与另一个文本文档上的代码匹配时,我需要获取与之关联的价格,但无法确定如何进行

while (!purchasesFile.eof())
{
    purchasesFile >> PurchaseItem >> purchaseQty;


    cout << purchaseNum << "  " << PurchaseItem << "  " << setw(4) << 
    purchaseQty << "  @ " << dollarSign << endl;

    int n = 0;  
        if (inventoryRec[n].itemCode != PurchaseItem)
        {
            inventoryRec[n+1];
        }
        else 
        {
            cout << inventoryRec[n].itemPrice << endl;
            inventoryRec[n+1];
        }

    if (PurchaseItem == inventoryRec[itemCount].itemCode)
    {
        inventoryRec[itemCount].itemOnHand - purchaseQty;
        purchaseAmount = inventoryRec[itemCount].itemPrice * purchaseQty;

        cout << purchaseAmount << "  " << 
       inventoryRec[itemCount].itemOnHand;

        purchaseCount++;
    }


    purchasesFile >> purchaseNum;
}
purchasesFile.close();
while(!purchasesFile.eof())
{
采购文件>>采购项目>>采购数量;

cout代码中有几个语句不起作用:

inventoryRec[n+1];

inventoryRec[itemCount].itemOnHand - purchaseQty;
你要找的可能是STL地图之类的东西

typedef struct inventory_item_t {
    inventory_item_t(const std::string& item_code, double price, int quantity) :
        item_code(item_code),
        price(price),
        quantity(quanity) { }

    std::string item_code;
    double price;
    int quantity;
} inventory_item_t;

typedef std::map<std::string, inventory_item_t> inventory_items_t;

inventory_items_t inventory_items;

inventory_items.insert(make_pair("item1", inventory_item_t("item1", 1.0, 1)));
inventory_items.insert(make_pair("item2", inventory_item_t("item2", 1.1, 2)));
inventory_items.insert(make_pair("item3", inventory_item_t("item3", 1.2, 3)));

inventory_items_t::iterator inventory_item = inventory_items.find("item1");

if(inventory_item != inventory_items.end()) {
    std::cout << "Inventory Item found - item_code: ["
              << inventory_item->first
              << "], price: ["
              << inventory_item->second.price
              << "]"
              << std::endl;
} else {
    std::cout << "Inventory Item not found" << std::endl;
}
typedef结构库存项目{
存货项目(常数标准::字符串和项目代码,双倍价格,整数数量):
项目代码(项目代码),
价格(价格),,
数量(数量){}
std::字符串项_代码;
双倍价格;
整数;
}库存项目;
类型定义标准::映射库存项目;
库存物品\u t库存物品;
存货项目。插入(配对(“项目1”,存货项目(“项目1”,1.0,1));
存货项目。插入(配对(“项目2”,存货项目(“项目2”,1.1,2));
存货项目。插入(配对(“项目3”,存货项目(“项目3”,1.2,3));
库存项目:迭代器库存项目=库存项目。查找(“项目1”);
if(inventory\u items!=inventory\u items.end()){

std::cout FYI:你有问题吗?当商品代码匹配时,我不知道如何获得与商品代码位于同一数组位置的价格。当前输出使用std::vector。使用std::vector生活总是会更好