|
|
|
| Может кто подскажет почему привключении стандартных библиотек при помощи DevCPP все компилится нормально но на некоторых машинах приходится включать строку: using namespace std; - закономерности не понял. Подскажите может от настроек зависит(среда использовалась на разных машинах сразу после установки, настройки по умолчанию). | |
|
|
|
|
автор: .exp (18.03.2010 в 17:36) |
|
|
для: Miha_drinking_bout
(17.03.2010 в 15:28)
| | не замечал такое.
Фактически должны быть записи using namespace std; для того чтобы не делать
std::cout << std::endl; вместо cout << endl;
А так возможно уже в подключаемых файлах где-то объявлено это using
Try It Out - The using Declaration
The function declarations go in the header file compare.h as we discussed above:
// compare.h
namespace compare
{
double max(const double* data, int size);
double min(const double* data, int size);
} |
We will put the definitions for the functions in a separate .cpp file that will contain the following code:
// compare.cpp
#include "compare.h"
// Function to find the maximum
double compare::max(const double* data, int size)
{
double result = data[0];
for(int i = 1 ; i < size ; i++)
if(result < data[i])
result = data[i];
return result;
}
// Function to find the minimum
double compare::min(const double* data, int size)
{
double result = data[0];
for(int i = 1 ; i < size ; i++)
if(result > data[i])
result = data[i];
return result;
} |
All we need is a .cpp file containing the definition of main() to try the functions out:
// Ex5_09.cpp
// Using functions in a namespace
#include <iostream>
#include "compare.h"
using compare::max; // Using declaration for max
using compare::min; // Using declaration for min
int main()
{
double data[] = {1.5, 4.6, 3.1, 1.1, 3.8, 2.1};
using namespace std; // Using directive for standard library
const int dataSize = sizeof data/sizeof data[0];
cout << endl;
cout << "Minimum double is " << min(data, dataSize) << endl;
cout << "Maximum double is " << max(data, dataSize) << endl;
return 0;
} | (Wrox Press C++ tutorial) | |
|
|
|
|
|
|
|
для: .exp
(18.03.2010 в 17:36)
| | Спасибо за ответ. Но немного не понял - получается при подключении библиотеки не все функции требуют явного декларирования? А иногда те же исходники на одной машине отказываются компилироваться без включения этой строки когда на др. все проходит без проблем(devCpp, машины в основном winXP Pro,но есть и под XPHomeEd, Vista, Win7, 2008R2) проявляется в основном при включении "iostream" Может при установке DevCpp затупил где? | |
|
|
|