Здравствуйте, Алексей Одинцов, Вы писали:
АО>если бы у меня работник написал сортировкую массива с использованием своей функции-сортировки бабль сортом, я бы его уволил нахрен тут же...
А что бы ты сделал с сотрудником, который
не может написать функцию dec2hex()?
Здравствуйте, What, Вы писали:
W>Всё в принципе нормально, но в теле for нужно ещё открыть файл и где-нибудь его закрыть. А с STL всё очень просто и красиво:
...и неправильно:
W>W>std::cout << std::accumulate(std::istream_iterator<int>(std::ifstream("F:\\Temp\\in.txt")), std::istream_iterator<int>(), 0);
W>
template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
class istream_iterator: public iterator<input_iterator_tag, T, Distance, const T*, const T&>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef basic_istream<charT,traits> istream_type;
istream_iterator();
istream_iterator(istream_type& s);
istream_iterator(const istream_iterator<T,charT,traits,Distance>& x);
~istream_iterator();
. . .
};
Есть хитрый способ это обойти:
std::cout << std::accumulate(std::istream_iterator<int>(std::ifstream("F:/Temp/in.txt").ignore(0)), std::istream_iterator<int>(), 0);
(пойдет любой член, возвращающий istream&).
Здравствуйте, MShura, Вы писали:
MS>Строка MS>const char hexArr[16] = "0123456789ABCDEF";
MS>
MS>Объявляет именованную/инициализированную область памяти размером 16 байт и помещает её в секцию с аттрибутами read-only.
Какая секция?! Какие атрибуты?! Компилировать-то пробовал?
Change: In C++, when initializing an array of character with a string, the number of characters in the string (including the terminating ’\0’) must not exceed the number of elements in the array. In C, an array can be initialized with a string even if the array is not large enough to contain the string terminating ’\0’
Example:
char array[4] = "abcd"; // valid C, invalid C++
Rationale: When these non-terminated arrays are manipulated by standard string routines, there is potential for major catastrophe.
Effect on original feature: Deletion of semantically well-defined feature.
Difficulty of converting: Semantic transformation. The arrays must be declared one element bigger to contain the string terminating ’\0’.
How widely used: Seldom. This style of array initialization is seen as poor coding style.