|
rahulcrjk wrote: gives the string itself as the output and not the address where the character 'f' is stored
Because the << operator was overloaded for the char* type and it is implemented to display the string itself. STL provided overloads for a lot of different types and they implemented the way they like (here, it makes much more sense to output the string and not its address).
rahulcrjk wrote: Also what does '&number' mean when 'number' is a pointer.
I don't really understand what you mean but I guess you are asking what &numptr means (if I use the code you provided earlier) ? In that case it simply means that it is the address of the pointer (remember that pointers are variables too, so they also have an address, which can be stored in another variable, and so on ad infinitum ).
|
|
|
|
|
rahulcrjk wrote: Herecan say, numptr is a pointer to an integer and it has the address of the location where 5 is stored
good.
rahulcrjk wrote: char * number = "five is number";
However here is it right to say that the 'number' is a pointer to a char and stores the address of the first character in the string(f). If it is, then why does the statement,
cout<<number;
gives the string itself as the output and not the address where the character 'f' is stored.
Because:
(1) the string layout in memory is
ADDRESS VALUE
number 'f'
number + 1 'i'
number + 2 'v'
number + 3 'e'
number + 4 ' '
number + 5 'i'
number + 6 's'
number + 7 ' '
number + 8 'a'
number + 9 ' '
number + 10 'n'
number + 11 'u'
number + 12 'm'
number + 13 'b'
number + 14 'e'
number + 15 'r'
number + 16 '\0'
(2) the extraction operator << knows about (1).
rahulcrjk wrote: Also what does '&number' mean when 'number' is a pointer.
is the address of the variable who holds the pointer. For instance
int i;
int * p;
int * * pp;
int k;
i = 5;
p = &i;
pp = &p;
k = **pp + 2;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hoo ho, i get your question right, and you have no idea how i struggled with c++ before i coluds understand pointers, thats why they even made java, to eliminate the whole thing about pointers, but the minute you understand the, thats it..
Just know that pointers yes have 2 major refences or usage in c++.
It all depends on how you use them, but fact is , they do point to an address in memory, not the actual data.
Your question goes like this,
if i say
int my_number = 5;
int* my_pointer = #
the output ;
cout << my_pointer ; displays an address, sth like 45542945;
if i output ;
cout << *my_pointer; then i get the number 5;
this is to say, my_pointer, is a memory (RAM) address, and the value in *my_pointer is the value 5;
if when used with a character / string, the pointer will refence the address of the first character, then when i say
char* my_ptr = "this is a string";
cout <<my_ptr.
my pointer being an address of the 1st character, then i shoudl see the address output, not the whole string.
but thats not the case, why??? was that the question.
okay, one point you have right, the other point you are missing is that, a pointer when used to refence an array, it points to the first element of the array.
why do you think this is correct;
int nums[3] = {11,21,31};
int* nums_ptr = nums;
cout<< nums_ptr[0] ;
because when you do point an array (a string is a also an array), you can copy the whole array into a pointer one time.
and yuo know that an array is placed in (contigous) continuous memory locations, i.e. if 11 is in addres x, then 21 is in x+1, and 31.
so for integers if you want the third element of the array in that has been copied to an pointer, if you say nums_ptr[2], you wont get the address of the 3rd element, you'll get the value.
but again for integers if you say
cout<<nums_ptr;
you wont get all the elements of the array displayed on the screen like 112131, no, you get the address.
thats the only differents with characters since, an array of characters is treated like a string..
displaying the pointer wont display the adress of the fisrt character but the whole string.
try play with pointers, that's the weak and stronghold with c++, in that learning is abit confusing but once learnt it gives some crazy flexibility you wont get from any of it's neighbors..
|
|
|
|
|
1. I am using a std::map to store some values of keys
2. On startup of my function i am loading values to my map
3. I am storing values to my map by a http call which is returning the key and values from a file.
4. Now i have changed my configuration file and i want to reload the config map without restarting my process
5. lots of places i am already accessing this map
How safely i can reload my configurations?
Please need some idea and help
Regards,
Samba 
|
|
|
|
|
Soumyadipta wrote: 4. Now i have changed my configuration file and i want to reload the config map without restarting my process
5. lots of places i am already accessing this map
How safely i can reload my configurations?
With the limited information you've given at least I can only give a general answer...
You have to trigger the "reloading" procedure in some way.
If you by "accessing the map" mean that you're using the map from different threads, you also need to provide thread synchronization using a critical section or mutex.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi
I wrote a program with vc6 which when clicked on a file;
the full path of it returns to output (Like CString m_bitmap = "E:\\Documents\\1.bmp"),
So I want to do this to return the directory of file,
Does anyone know how can I do that and in which class I could return directory?
I don't need to return the current directory of my project and the type of variable is CString;
Please mail me the answer,
My mail is: mhghaeminia@yahoo.com
Thanks
|
|
|
|
|
David Crow already answered [^].
Anyway with MFC , using CPath will make your life simpler (you've to include atlpath.h ):
void CMyClass::GetDirectory( CString & szPath )
{
CPath path( szPath );
path.RemoveFileSpec();
szPath = (PCTSTR)path;
}
void CMyClass::OnBnClicked()
{
CString szBmpPath = _T("E:\\Documents\\1.bmp");
CString szBmpFolder = szBmpPath;
GetDirectory(szBmpFolder);
AfxMessageBox(szBmpFolder);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am in charge of a large number of dll's written in MFC. I have made a decision to convert them to COM interfaces. I studied the subject and decided ATL is the best answer. Problem is:
I cannot call the old dll methods without getting a LNK2019 error.
The IDE is VS2003. I read something about there being a issue with VS2003 with the 'attribute' keyword.
A nudge in the right direction would be highly appreciated.
|
|
|
|
|
Member 3480232 wrote: I cannot call the old dll methods without getting a LNK2019 error.
Which means that you're doing implicit linking, i.e. you're not calling ::LoadLibrary() and ::GetProcAddress() to make use of your libraries.
This also means that you need to link with the .lib file generated in the build process of the library you're trying to use.
Now to the obvious question....: have you added the .lib file to the "additional libraries" in your project settings?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Right on all counts. The original job was done by myself, so everything is as I hoped it should be. I also include the old job.h file with the cplusplus override added.
Its obvious I am doing something wrong!
As an afterthought, part of the decision to do this had to do with the schlepp of using LoadLibrary, GetProcAdress or DllImport and possibly speed of linking as well.
|
|
|
|
|
|
Pearson_Bee wrote: assume that the length of pBuffer-BUFFERSIZE is bigger than or equals the length of
the buffer of socket,Is there possible that data in the buffer of socket is not
retrieved clearly after calling recv() one time?
Assume I've understood properly your question: the answer is no.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
sorry I made you misunderstood,
would you like to detail this sentence from MSDN?
---"For connection-oriented sockets (type SOCK_STREAM for example),
calling recv will return as much information as is currently
available—up to the size of the buffer supplied."
is it mean every bytes of data will be retrived after recv() at one time? as long as the size of the buffer supplied is big enough?
thanks in advanced.
|
|
|
|
|
Pearson_Bee wrote: is it mean every bytes of data will be retrived after recv() at one time? as long as the size of the buffer supplied is big enough?
The statement
as much information as is currently available, up to the size of the buffer supplied
looks to me clear, accurate and in contrast with your interpretation.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Pearson_Bee wrote: is it mean every bytes of data will be retrived after recv() at one time? as long as the size of the buffer supplied is big enough?
No!
It means that recv() will return as many bytes as it has available,
up to the number of bytes you've requested (indicated by the number
you pass as the "len" parameter). This could be one byte, all the bytes
you've requested, or any number of bytes in between.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's VERY bad etiquette to delete your question after you get an answer
|
|
|
|
|
Hi all,
In my application ,on fromview i m using a List, to fill the list i m using number of function on OnInitialUpdate() Function.
when list fill than the mouse cursor is in wait mode and application looks like hang.
i want to add any dilog box/message box without any button it inform the status or message like Please wait, and other processing continue in background.
when list is filled the dilog box/message box closed automatically.
please can anybody help me for this.
thank in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
"_$h@nky_" wrote: when list fill than the mouse cursor is in wait mode and application looks like hang.
Gather the information supposed to be displayed in the list box in a secondary thread while you have one item in the list saying something like "Updating..." or similar.
When the thread has finished building a e.g. std::list with the elements for the list box, you walk through the list and add the elements to it.
This way the application becomes responsive right away, but you inform the user that there is more data to be displayed in a while.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
But i m using a ListCtrl,because i need a type of ReportView List.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
"_$h@nky_" wrote: But i m using a ListCtrl,because i need a type of ReportView List.
The same mind set applies:
prepare and format the data in a secondary thread before updating the UI element to make the UI updating process as fast as possible in order to have the application remain responsive.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Can you please explain me with any example.
thnks alot.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
"_$h@nky_" wrote: Can you please explain me with any example.
No.
This is mainly a design issue, for which I have suggested a solution.
How to implement this design is for you to figure out, which shouldn't be too hard.
If you have more specific questions in the nature of "how do I tell my main thread when the computation has finished", I'll be glad to answer them. But serving it on a silver plate would prevent you from learning and besides I don't have the time to do it.
To give you an idea I suggest you read this article[^] regarding worker threads. It's the best in my opinion.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
hi <your name="">, maybe you might not be conversant with threads or multithreading, which simply means, having many threads running at the same time, in one program, so am going to easily illustrate how you can overcome your problem using just one thread.
i advice you place your code for filling the list in a function then you call the function in the Oninitupdate or since you want the list loaded at progream start. this is better and clearer than filling so much code in the oninitUpdate() fiuntion.
so this is what we shall do, i hope you can tell the number of items you are putting in the list,
Put a progress control ,
Add a control variable to it, call it "m_ctlProgress" using the wizard.
//////////////////////
int nCounter = 0;
int nNumberOfRecords = <your number="" of="" records="">
ctlProgress.SetRange(0,nNumberOfRecords );
for <loop trough="" your="" data="" as="" you="" fill="" list="">
{
//////////////////////////
Your filling code here
/////////////////////////
nCounter++;
m_ctlProgress.SetPos(nCounter);
}
then call the function from wherever, from the Oninit.. or when a certain button is clicked, etc
|
|
|
|
|
Some hints...:
- You replied to the wrong person.
- The function you're referring to is
OnInitialUpdate() , nothing else. OnInitialUpdate() is called before the view is displayed, which means that your progress bar probably won't even show if your code is called from OnInitialUpdate() .- You have not formatted your code using <pre></pre> tags, which makes it hard to read.
- At best, the user will still experience a non-responsive application even if your advice is followed.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all,
I am working on VC-2008, my problem is i have made a .h file and had defined some variables in it. And in other files i have used those global variables using extern. Now, when i compile the program its giving an error error LNK2001: unresolved external symbol "char Platform" (?Platform@@3DA), and if i include that .h file as header file it gives error variables already defined....
How can i do this??
Thanks in advance
|
|
|
|
|