Incorrect flow ost



  • namespace Product
    {
    string Name_product;
    vector <string> save_name_product;
    double sum_product(0);
    vector <double> save_sum_product;
    int count_product(0);
    vector <int> save_count_product;
    }
    using namespace Product;
    
    int main()
    {
            time_t rawtime;
            struct tm * timeinfo;
            time(&rawtime);
            timeinfo = localtime(&rawtime);
    
        setlocale(LC_ALL, "RUS");
        // руссификация консоли.
        // Открываем и записываем в фаил.
        string name;
        cout << " Назовите фаил:" << endl;
        cin >> name;
        ofstream ist(name.c_str());
        if (!ist) cout << " Фаил не открыт";
        string oname;
        cout << " В какой фаил сохранить данные?" << endl;
        cin >> oname;
        ofstream ost(name.c_str());
        if (!ost) cout << " Фаил не открыт!";
        system("cls");
    
        while (cin >> Name_product >> count_product >> sum_product)
        {
            system("cls");
            // затирания консоли , набраных значений.
    
            save_name_product.push_back(Name_product); // имя продукта.
            save_count_product.push_back(count_product); // кол-во продукта.
            save_sum_product.push_back(sum_product); // сумма продукта.
    
            for (int i = 0; i < save_name_product.size(),
                i < save_count_product.size(), i < save_sum_product.size(); ++i)
    
                if(i == 0 || save_name_product[i-1]!=save_name_product[i])
                    //если повторяется строка , не пишем.
            {
                cout << i << "." << save_name_product[i] << setw(6)
                    << save_count_product[i] << "count." << setw(6) << "sum."
                    << save_sum_product[i] << "___"
                    << asctime(timeinfo); 
                    // время / дата на консоль.
    
                // пишем даные базы в фаил.
                ost << i << "." << save_name_product[i] << setw(6)
                    << save_count_product[i] << "count." << setw(6) << "sum."
                    << save_sum_product[i] << "___"
                    << asctime(timeinfo);
            }
        }
    }
    

    The record is incorrect, all the elements taken are repeated several times and mixed.

    I've got to do this.
    It's all my language skills now.
    I'll be very grateful for your help, studying with++ on my own.



  • You need to take the cycle. for cycle while

    I understand the cycle. while must first complete all the elements of the vectors. And that's the cycle. for I must take these elements into the file.

    I mean, cycles should follow a friend like,

    while ( условие )
    {
        //....
    }
    

    for ( параметры )
    {
    // ....
    }

    Not being invested in each other.
    Keep in mind that the condition is in this cycle.

    for (int i = 0; i < save_name_product.size(),
    i < save_count_product.size(), i < save_sum_product.size(); ++i)

    Doesn't make much sense, because it's completely equivalent to the condition in the cycle.

    for (int i = 0; i < save_sum_product.size(); ++i)

    In view of the fact that a comma operator is used in the first cycle, which only returns the value of the last Operanda.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2