Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Veranschaulicht, wie Ausdruck,Protokoll, und Funktionen log10 Standardvorlagenbibliothek (STL) in Visual C++ verwendet.
template<class T>
valarray<T> exp(
const valarray<T>& x
);
template<class T>
valarray<T> log(
const valarray<T>& x
);
template<class T>
valarray<T> log10(
const valarray<T>& x
);
Hinweise
Hinweis |
|---|
Die Klasse/Parameternamen im Prototyp stimmen nicht mit der Version in der Headerdatei ab.Einige wurden geändert, um die Lesbarkeit zu verbessern. |
Beispiel
// explog10.cpp
// compile with: /EHsc
#include <iostream> // for i/o functions
#include <valarray> // for valarray
#include <math.h> // for exp(), log(), and log10()
using namespace std;
#define ARRAY_SIZE 3 // array size
typedef valarray<double> DB_VARRAY;
int main() {
// Set val_array to contain values 1, 10, 100 for the following test.
DB_VARRAY val_array(ARRAY_SIZE);
int i;
for (i = 0; i < ARRAY_SIZE; i++)
val_array[i] = pow((double)10, i);
// Display the size of val_array.
cout << "Size of val_array = " << val_array.size() << endl;
// Display the content of val_array before calling exp, log, and
// log10 functions.
cout << "val_array values:";
for (i = 0; i < ARRAY_SIZE; i++)
cout << " " << val_array[i];
cout << endl;
// rvalue_array to hold the return value from calling the exp,
// log, and log10 functions.
DB_VARRAY rvalue_array;
// ----------------------------------------------------------------
// exp() - display the content of rvalue_array
// ----------------------------------------------------------------
rvalue_array = exp(val_array);
cout << "After calling exp():";
for (i = 0; i < ARRAY_SIZE; i++)
cout << " " << rvalue_array[i];
cout << endl;
// ----------------------------------------------------------------
// log() - display the content of rvalue_array
// ----------------------------------------------------------------
rvalue_array = log(val_array);
cout << "After calling log():";
for (i = 0; i < ARRAY_SIZE; i++)
cout << " " << rvalue_array[i];
cout << endl;
// ----------------------------------------------------------------
// log10() - display the content of rvalue_array
// ----------------------------------------------------------------
rvalue_array = log10(val_array);
cout << "After calling log10():";
for (i = 0; i < ARRAY_SIZE; i++)
cout << " " << rvalue_array[i];
cout << endl;
}
Output
Size of val_array = 3
val_array values: 1 10 100
After calling exp(): 2.71828 22026.5 2.68812e+043
After calling log(): 0 2.30259 4.60517
After calling log10(): 0 1 2
Anforderungen
Header: <valarray>
Hinweis