Code trên là 100% standard C++, không có gì sai hết, compiler Visual C++ 6.0 có vấn đề thì đúng hơn. Vào phần help của nó đọc xem nó đòi hỏi thế nào, hoặc :
google : Visual C++ 6.0
C++ Code:
//Fig. 5.6: fig05_06.cpp // Compound interest calculations with for. #include <iostream> using std::endl; using std::fixed; #include <iomanip> using std::setw; // enables program to set a field width using std::setprecision; #include <cmath> // standard C++ math library using std::pow; // enables program to use function pow int main() { double amount; // amount on deposit at end of each year double principal = 1000.0; // initial amount before interest double rate = .05; // interest rate // display headers // set floating-point number format // calculate amount on deposit for each of ten years for ( int year = 1; year <= 10; year++ ) { // calculate new amount for specified year amount = principal * pow( 1.0 + rate, year ); // display the year and the amount } // end for return 0; // indicate successful termination } // end main
Mình chạy băng visual C++ 6.0 thì nó báo lỗi
--------------------Configuration: fig05_06 - Win32 Debug--------------------
Compiling...
fig05_06.cpp
e:\view\c++ how to program\cpphtp5_examples\ch05\fig05_06\fig05_06.cp p(13) : error C2039: 'pow' : is not a member of 'std'
e:\view\c++ how to program\cpphtp5_examples\ch05\fig05_06\fig05_06.cp p(13) : error C2873: 'pow' : symbol cannot be used in a using-declaration
Error executing cl.exe.
fig05_06.exe - 2 error(s), 0 warning(s)
Mình nghĩ là do thư viện <cmath> bị lỗi. Mong các bạn chỉ bảo cách khắc phục
Vui lòng để code vào tag code. Đọc Nội quy để biết thêm chi tiết
Đã được chỉnh sửa lần cuối bởi Kevin Hoang : 11-04-2008 lúc 02:34 AM. Lý do: Nhắc nhở hoài
Code trên là 100% standard C++, không có gì sai hết, compiler Visual C++ 6.0 có vấn đề thì đúng hơn. Vào phần help của nó đọc xem nó đòi hỏi thế nào, hoặc :
google : Visual C++ 6.0
Bạn bỏ dòng using std::pow; thử xem, đơn giản là nó không thuộc std, chỉ cần include <cmath> là xài được pow ^ ^.
"what you don't use you don't pay for" (Bjarne Stroustrup).