プログラムにコマンド ライン引数を追加しようとしています。だから私は実験していましたが、私の人生に対するこのインテリセンスの警告を理解することはできません. 「)」が必要だと言い続けますが、その理由はわかりません。
気に入らないコードは次のとおりです。
// Calculate average
average = sum / ( argc – 1 );
次に、減算演算子に下線を引きます。以下は完全なプログラムです。
#include <iostream>
int main( int argc, char *argv[] )
{
float average;
int sum = 0;
// Valid number of arguments?
if ( argc > 1 )
{
// Loop through arguments ignoring the first which is
// the name and path of this program
for ( int i = 1; i < argc; i++ )
{
// Convert cString to int
sum += atoi( argv[i] );
}
// Calculate average
average = sum / ( argc – 1 );
std::cout << "\nSum: " << sum << '\n'
<< "Average: " << average << std::endl;
}
else
{
// If invalid number of arguments, display error message
// and usage syntax
std::cout << "Error: No arguments\n"
<< "Syntax: command_line [space delimted numbers]"
<< std::endl;
}
return 0;
}