|
hi all
is there any help to say , what is the best Book Or Reference for Visual c++ .
I'm new in visual c++
thanx very lot
s_mostafa_h
|
|
|
|
|
If one book could take you from beginner to intermediate programmer, (in Visual C++) it would have to be Ivor Horton's "Beginning Visual C++ 6" or there are versions for VC++ 2005 and VC++ 2008.
They are all basically the same except the newer ones add some odd chapters on WinForms and a small dose of .NET for completeness.
First half of the book teaches C++, the second half is about Windows programming. MFC is the dominant class library used.
|
|
|
|
|
I don't think that there is single book which is the final reference of entire VC++ programming stuffs. From my experience, I recommend 4 books, by which you can pass most of the hurdles that a typical windows programmer will encounter.
1) If you are a beginner and want to learn the basics of windows programming then,
- Programming Windows by Charles Petzold - Its a classic.
2) If you want the reference for MFC, then
- Programming MFC by Jeff Prosise.
3) If you want to do some kernel stuff, then.
- Programming Applications for Microsoft Windows by Jeffrey Richter.
4) If you want a reference for debugging, then
- Debugging Applications by John Robbins.
Regards,
Jijo.
________________________________
http://weseetips.com - Daily Visual C++ technical tips.
|
|
|
|
|
thanx ,
now i want to know is there any differ between Visual C++ 6 & VC++ 2005 or ... other version actually.
sometimes this very important to know this .
rgds
s_mostafa_h
|
|
|
|
|
Indeed. They differs a lot.
1) Visual Studio 2005 stays more close to C++ language specifications. Where in VC 6.0 you might miss some language features. For instance try-catch block in body of constructor. I couldn't compile it in my VC 6.0 SP5.
2) But don't under-estimate VC 6.0. I've to admit that VC 6.0 is one of the best IDE that ever build. You see, still its being used by lot of companies for lot of products. Its still popular now.
3) In VC++ 2005 supports .net platform where VC++ 6.0 don't.
Have a look at Wiki[^] about the different versions of Visual C++.
Regards,
Jijo.
________________________________
http://weseetips.com - Visual C++ technical tips.
|
|
|
|
|
And see www.cplusplus.com.
|
|
|
|
|
I'm getting the feeling that when using strtol and I'm interested in the global errno value before and after the call to strtol, I need to reset the global errno to zero (or some nothing value) in order to detect an error.
The documentation only says to check it before and after but if it was already set to ERANGE before the call and it overflows, it will still be ERANGE afterward.
Is it standard practice to reset errno explicitly before using strtol?
|
|
|
|
|
Unless LONG_MAX and LONG_MIN are valid input values, you can check return value first then check errno without being busy with errno before the function call.
<br />
long lVal = strtol(pszNum, &pEndPtr, 10);<br />
if((LONG_MAX == lVal) || (LONG_MIN == lVal))<br />
{<br />
}<br />
Your concern is valid when input value equals either LONG_MAX or LONG_MIN. Because, it returns LONG_MAX or LONG_MIN (defined limits.h) if an overflow (or underflow) condition occurs.
modified on Saturday, April 26, 2008 6:14 PM
|
|
|
|
|
Ozer Karaagac wrote: Unless LONG_MAX and LONG_MIN are valid input values
They are valid inputs and will not cause an error.
Ozer Karaagac wrote: Your concern is valid when input value equals either LONG_MAX or LONG_MIN.
Any string that equates to an integral value larger than these as well.
I guess I'm still unsure whether I can just reset errno before the call to strtol or am I required to read it, reset it, call strtol, check error, restore errno to it's original value?
|
|
|
|
|
I will try to help your decision.
For larger decimal values, you may consider to use different functions like _atoi64() or strtod() to widen the limits.
When it comes to errno, it is an immediate value. You don't have to save/restore errno unless you are going to use it afterwards. I think, this is not a good practice also. If you plan to use that value later, you should save it in another variable. Thus, resetting it before the function call is enough to see whether LONG_MAX is real result or the error flag.
Runtime library functions change this variable only when an error occurs and report the situation by returning an error value. It's also beneficial to inspect runtime library source codes that may come with your compiler (in MSVCDIR\CRT\SRC for MSVC).
I did inspect the strtol() source code just now. And it only assigns ERANGE value to errno in one line. So, any value other than ERANGE will not be related to strtol() also. But,
if((LOMG_MAX == lVal) || (LONG_MIN == lVal))
{
if(ERANGE == errno)
else
}
modified on Sunday, April 27, 2008 11:15 AM
|
|
|
|
|
Thanks for the guidance.
I think I have something upwards of 100+ books on C/C++, MFC, Windows, etc...
not to mention MSDN and none of them are very explicit about resetting errno before the call to strtol.
Granted, what they do say about it and what intuition tells me is getting pretty clear. Your comments have helped.
|
|
|
|
|
Hi All,
Having romped in the Elysian field that is C# I'm now being forced to learn C++. To this end I've managed to crawl through this book to Chapter 8 but I'm having trouble with 8-3 - using iterators instead of passing a vector.
Briefly, how is the template supposed to operate on the vector if the vector isn't passed in one form or another??
I have, without doubt, got the wrong end of the stick here...
I'm not looking to be spoon fed the answer (I don't expect anything in C++ to be easy), but an indication of how to proceed would be of immense help.
Thanks
Si
|
|
|
|
|
I think you are making a wrong assumption that people here have read the C++ book you are reading. Always ask complete question rather than pointing to the book.
If I understand question completely that you are asking how a function which is passed an iterator will operate on vector. Well the iterators point to the vector! Think of iterators as pointers so when you pass an iterator to the vector you are passing a pointer to the vector. Now iterator is not exactly a pointer but it follows pointer semantics i.e. you can deference it *it, increment it ++it, decrement it --it, etc.
If you want to read more about STL then try SGI STL[^] and it has good introduction to iterators[^].
-Saurabh
|
|
|
|
|
Hi Saurabh & thanks for replying. Actually, the assumption I was making,probably wrongly, was that only people familiar with the book would reply but perhaps I should have made that more clear; in any case apologies.
To make the question more general - we have a template function that takes a vector as an argument:
template <class T>
T median(vector<T> v)
{...}
The task is this: instead of passing the vector ('v')by value, rewrite the function to operate on iterators.
This is probably v. trivial but has me stumped.
Here's the code I have so far if anyone's interested
#include "stdafx.h"
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
T median(vector<T> v)
{
typedef typename vector<t>::size_type vec_sz;
vec_sz size = v.size();
if (size == 0)
throw domain_error("median of an empty vector");
sort(v.begin(), v.end());
vec_sz mid = size/2;
return size % 2 == 0 ? (v[mid] + v[mid-1]) / 2 : v[mid];
}
int main()
{
vector <float> v1;
vector <int> v2;
for (int i=0; i < 10; i++)
{
v1.push_back(i+5);
v2.push_back(i+5);
}
int size = median(v1);
double sf = median(v1);
cout << "The median of the float vector v1 is " << median(v1) << endl;
cout << "The median of the int vector v2 is " << median(v2)<< endl;
system ("pause");
return 0;
}
I think what I'm asking is that if the vector isn't present in the template function, how can iterators like begin() & end() possibly work on it?
Also, why does C++ have to be so awkward and obscure and frustrating (actually no reply needed to that - I know you all love it and I don't want to start a row).
Thanks
Si
|
|
|
|
|
Okay first lets consider an example using pointers. Lets say there is an array of ints.
int array[11];
Now let us pretend that this array is only of size 10. Last element is used to mark as end of the vector.
int* begin = &array[0];
int* end = &array[10];
Now we can write a mean function as (I choose mean because its easier to show concept of iterators):
int Mean(int* begin, int* end)
{
int _mean = 0;
int _count = 0;
while(begin != end)
{
_mean += *begin;
_count++;
begin++;
}
return _mean/_count;
}
You will notice two things about this code. First, I have not passed array at all but I am able to compute mean. Second, the last location that we reserved in the array is used to find when to stop iterating an array. Thats it, this is the concept of STL iterators. Just imagine pointer is wrapped in an class and we call it iterator.
We can write mean function using generic container as:
template<typename InputIterator>
typename InputIterator::value_type Mean(InputIterator begin, InputIterator end)
{
typename InputIterator::value_type _mean = 0;
int _count = 0;
while(begin != end)
{
_mean += *begin;
_count++;
begin++;
}
return _mean/_count;
}
Now lets see the requirement in the type of InputIterator. begin and end are used in 3 places in Mean function - begin != end, *begin, and begin++. So the iterator class should should only support these operators. Notice all these three operations are supported by pointer as well. So you can call this mean function for arrays we well.
double points[11] = {0};
double mean = Mean(&points[0], &points[10]);
You can also do this:
std::vector<int> points;
points.push_back(1.0);
points.push_back(2.0);
points.push_back(3.0);
.
.
.
points.push_back(10.0);
double mean = Mean(points.begin(), points.end());
Hope this makes things clear.
-Saurabh
modified on Sunday, April 27, 2008 8:55 AM
|
|
|
|
|
Hi Saurabh,
Yes indeed that makes things crystal clear! - thank you very much for a brilliant answer. In my head I somehow equated iterators with variables. But, then, I am an idiot so that's not particularly surprising. What do iterators do? They iterate, of course: 1,2,3,4,etc. etc. So if iterators are passed you aren't passing fixed values but the ability to process through a range that they contain. How could I be so thick??
Thanks again for your patience and a really clear and concise answer.
Si
|
|
|
|
|
Hey Oliver,
You are most welcome. You got it correctly. Iterators iterate over a container and more importantly they iterate through a given range. So using iterators you can process only a part of array which is not possible when passing array itself and its size without extra arguments.
-Saurabh
|
|
|
|
|
Hi Saurabh,
OK here's the code I've knocked together as a solution:
#include "stdafx.h"
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <vector>
using namespace std;
template<typename inputiterator>
typename InputIterator::value_type median(InputIterator begin, InputIterator end)
{
vector<typename> v;
typedef typename vector<typename>::size_type vec_sz;
//After the while loop, below, begin == end so can't use the while loop again.
//So chuck everything in a vector and work on that
//Does this save processing over simply passing a vector into
// the template?
//Is this the way it should be done??
//Who knows - all I know is it works and I can finally move on
//Some people do this for fun, you know...
while (begin != end)
{
v.push_back(*begin);
begin++;
}
vec_sz size = v.size();
if (size == 0)
throw domain_error("median of an empty vector");
sort(v.begin(),v.end());
vec_sz mid = size/2;
return size % 2 == 0 ? (v[mid] + v[mid-1]) / 2 : v[mid];
}
int main()
{
vector <int> v2;
v2.push_back(3);v2.push_back(13);v2.push_back(7);v2.push_back(5);v2.push_back(21);v2.push_back(23);
v2.push_back(23);v2.push_back(40);v2.push_back(23);v2.push_back(14);v2.push_back(12);
v2.push_back(56);v2.push_back(23);v2.push_back(29);
//median of v2 shuld be 22. See http://www.mathsisfun.com/median.html
cout << "The median of the int vector v2 is " << median(v2.begin(),v2.end())<< endl;
system ("pause");
return 0;
}
The only niggle is that after using the while loop to get the size, 'begin' equalled 'end' and so I couldn't iterate through again to find the mid point. In the end I created a vector and put everything in there. This kind of made sense but I can't help feeling I'm missing something by using another vector... perhaps there is a way to reset the iterators after they have been used once (i.e. in the while loop)
Cheers
Si
|
|
|
|
|
Okay try this code.
template<typename InputIterator>
typename InputIterator::value_type median(InputIterator begin, InputIterator end)
{
size_t _size = end - begin;
if(_size == 0)
{
throw std::domain_error("median of an empty vector");
}
sort(begin, end);
size_t mid = _size/2;
return _size % 2 == 0 ? (*(begin+mid) + *(begin+mid-1)) / 2 : *(begin+mid);
}
sort function in STL needs that InputIterator be a model of RandomAccessIterator i.e. ith element in the array can be accessed using array[i]. Thus Inputiterator for Median should also be RandomAccessIterator. For random iterators we can determine size of array simply by subtracting last iterator from the first iterator (they behave exactly like pointers to array) Rest all is just like an array, simple pointer arithmetic. This function has a serious side effect that it sorts the original v2. It you don't want to sort it then try nth_element function in the <algorithm class="">.
-Saurabh
|
|
|
|
|
Of course - begin and end reference the place in the vector as well as the contents of that place. Superb - I think that covers that question pretty completely.
Thanks once again, Saurabh - you've saved me a whole load of time trying to sort this one out.
Question 8-4 next...what's the betting I'll be back on here tomorrow !!
Cheers,
Si
|
|
|
|
|
You are most welcome Oliver.
-Saurabh
|
|
|
|
|
Hi,
I was just trying to get one of the sample programs compiled. It has customized entry point function configured using directive
#pragma comment (linker, "/entry:\"something\"") which the compiler didn't seem to recognize, it returned something like "error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup LIBCMTD.lib". How can I get this right? I'm using VS 2005.
Thanks,
|
|
|
|
|
I think the problem is in the syntax. There is no need for quotes for the function name. Try this.
#pragma comment(linker, "/entry:something")
-Saurabh
|
|
|
|
|
how to write other language font(text) in edit control not english
Trioum
|
|
|
|
|