Рассмотрим эту программу:
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
fstream file;
int line_count = 0;
int months;
string name_file;
std::cout << "Please input the file name for your report file: ";
std::cin >> name_file;
if (name_file != "load_report.txt")
{
std::cout << "Invalid report file!\n";
exit(1);
}
std::cout << "Please provide the number of months to consolidate: ";
std::cin >> months;
if (months <= 0)
{
std::cout << "You need to have at least one month in order to"
<< " consolidate your sales.\n";
exit(1);
}
std::cout << "\n";
file.open(name_file, ios::in);
if (file.is_open())
{
string line;
while (getline(file, line))
{
line_count++;
}
}
else
{
std::cout << "Could not open file!\n";
exit(1);
}
file.close();
file.open(name_file, ios::in);
vector<float> a(line_count);
int k = 0;
if (file.is_open())
{
for (auto & val : a)
{
file >> val;
}
}
else
{
std::cout << "Could not open file!\n";
exit(1);
}
file.close();
int loops = line_count / months;
for (int i = 0; i < loops; ++i)
{
float sum = 0;
std::cout << "Month ";
for (int j = 0; j < months; ++j)
{
std::cout << i * months + j + 1 << " ";
sum += a[i * months + j];
}
std::cout << "sales: $" << sum << "\n";
}
return 0;
}
Запуск make stylecheck
возвращает следующее:
16369 warnings generated.
/home/bl71/bl71/prob-02/prob-02-main.cpp:64:17: warning: calling a function that uses a default
argument is disallowed [fuchsia-default-arguments-calls]
vector<float> a(line_count);
^
/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:507:29: note: default
parameter was declared here
vector(size_type __n, const allocator_type& __a = allocator_type())
^
Есть ли аргумент, через который можно передать это предупреждение go прочь ? Это программа, которую я пытаюсь написать, которая загружает ежемесячный отчет из файла отчета и отображает консолидированные продажи за заданный диапазон месяцев. В моем каталоге файл load_report.txt
был создан вручную, и я использую эту программу, чтобы прочитать его содержимое, используя fstream
. make stylecheck
проверяет внутреннюю документацию.