|
Hi all,
I am trying to trim a string and store the values in some variable.
i.e
I have
CString str = sample(1,2,3,4,5);
I want to store the values as
x1=1,x2=2,x3=3......so on.
Any idea how can i proceed will be thankful
Thanks in advance
Raj
|
|
|
|
|
I assume you mean
CString str = sample("1,2,3,4,5");
You can use std::stringstream, ::strtok(), CString::Find(), or maybe boost::split(). Try each of them and see how they differ.
|
|
|
|
|
Dear, Firstly assign object of CString correctly.
modified on Wednesday, August 25, 2010 2:44 AM
|
|
|
|
|
What's wrong with assigning a variable from a function call?
|
|
|
|
|
No problem, that's
CString sample(int a, int b, int c, int d, int e)
{
CString str;
str.Format("%d,%d,%d,%d,%d", a,b,c,d,e);
return str;
}
CString str = sample(1,2,3,4,5);
just pure humour!
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]
|
|
|
|
|
raju_shiva wrote: CString str = sample(1,2,3,4,5);
The above instruction is not correct.
Supposing it is:
CString str = "sample(1,2,3,4,5)"
I would use CStringT::Tokenize [^], have a look at the sample code provided.
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]
|
|
|
|
|
CPallini wrote: Supposing it is:
CString str = "sample(1,2,3,4,5)"
Actually i am reading it from edit box as a CString.
i.e
CString str = "sample(1,2,3,4,5)"
I am trying with this code
CString str = "sample(1,2,3,4,5)",str1,str2;
str1 = str .Left(str .Find("("));
str2 = str .Right(str .Find("("));
str.Left is working fine
I am getting the result as sample
But str.Right i am not getting the required result as 1,2,3,4,5).
I am getting 3,4,5
What i am doing wrong
Thanks
Raj
|
|
|
|
|
raju_shiva wrote: str1 = str .Left(str .Find("("));
str2 = str .Right(str .Find("("));
Change to:
int pos = str.Find("(");
str1 = str.Left(pos);
str2 = str.Right( str.GetLength() - pos - 1);
However, I still would use Tokenize for the overall task.
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]
|
|
|
|
|
Hi,
Thank you for your reply.
I have used for() loop and find to split the string.
As i am not familar with Tokenize,thats why i did not used it.
Thanks
Raj
|
|
|
|
|
I am giving example as your requirement.
eg.
CString str = "sample(1,2,3,4,5)",str1,str2;
int curPos= 0;
str1 = str.Tokenize("()",curPos);
Output: str1 = 1,2,3,4,5
|
|
|
|
|
Hey
I used DeleteVolumeMountPoint function to remove a USB drive (E from my machine. Now i want to bring that back. I tried re-booting and that doesn't seems to help.
I think calling SetVolumeMountPoint function will bring it back. But that function needs the GUID of USB drive, which i don't have.
Any ideas how to get the USB drive(volume - E:\) back?
Can i do that via regedit? If so, how?
THanks in advance
|
|
|
|
|
Got a system restore point from before you deleted it?
[If not, why not? ]
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
If you want to do it programmatically, there is some work to do around the SetVolumeMountPoint function.
The easiest way is to do it from the Control Panel: open the Administrative tools and run Computer management, then select the section Disk management. There you can see all the disks, both removable and not; you should right-click on the USB drive and select Change drive letter and path (or Assign drive letter and path, or similar).
Cheers,
Sauro
|
|
|
|
|
Hey Sauro,
That worked awesome!
Thanks a lot.
|
|
|
|
|
I'm using Visual C++ 6 service pack 6 on XP. According to the documentation for that version, Advanced Windows Extentions (AWE) allows users to access physical memory beyond the 2 GB boundary for a process. There is an example in the documentation:
http://msdn.microsoft.com/en-us/library/aa366531(VS.85).aspx
I've had trouble linking to kernel32.dll to make this work. However, the kernel32.dll(2009) in Windows/system32 has the functions so I used LoadLibrary() to explicitly link to that kernel32.dll. Unfortunately, even on a system with 2.96 GB of RAM, running ONLY the simple example, I cannot get VirtualAlloc() to successfully reserve memory over 1100 MB (it does work at 1100 MB and below). I am using the VirtualAlloc from the 2009 kernel32.dll.
*****
typedef LPVOID (WINAPI *LPVIRT)(LPVOID lpAddress,SIZE_T dwSize,DWORD flAllocationType,DWORD flProtect);
LPVIRT lpVirt;
HMODULE hHandle = LoadLibrary("kernel32.dll");
// Reserve the virtual memory.
lpVirt = (LPVIRT)GetProcAddress(hHandle, "VirtualAlloc");
lpMemReserved = (*lpVirt)( NULL,m_uMBytes*0x100000,MEM_RESERVE | MEM_PHYSICAL,PAGE_READWRITE );
if( lpMemReserved == NULL )
{
TRACE("Cannot reserve memory.\n");
return;
}
*****
With 2.96 GB, shouldn't I be able to reserve more than 1100 MB? How can I do it?
|
|
|
|
|
Hi,
1.
please use PRE tags when showing code snippets, as it improves readability.
2.
on 32-bit Windows, the user part of the virtual address space is limited to 2GB (per process). There is a way to extend that to 3GB, use Google to locate it. I have the impression you didn't do it, since you didn't mention it at all. On 64-bit Windows, the situation obviously is quite different.
3.
within 2GB virtual space, I'm not very surprised you get only some 1.1GB; as your own code and data is in that same 2GB space. I don't know what the default addresses for those would be; a link map should contain all such info. Have a look at the linker switches and ask for a map; then maybe look for more switches if you want to alter the virtual addresses used by code and data.
4.
I haven't used MEM_PHYSICAL yet, and haven't read up on all the doc, however I would be concerned it may also imply you are asking for contiguous physical memory (mind you, I'm not sure here). Finding such amount of contiguous memory is pretty unlikely.
5.
Maybe you should tell a bit about the overall goals; just maybe there is a better approach for what you are after.
|
|
|
|
|
Thank you very much for your prompt reply. My overall goal is to be able to have my application access memory beyond the 2GB boundary so that it can allocate physical memory beyond the 2GB boundary and I am able to allocate 2 to 3 (maybe more?) GBs of memory. One solution you mentioned (the 3GB extension) is described here:
http://msdn.microsoft.com/en-us/library/ms189334(SQL.100).aspx
This solution however affects the allocation of memory for every application on the system, and is not something I really want to do. I just want my particular application to be able to allocate beyond the boundary.
Note that the link above mentions AWE, which I am trying to use. Note that the diagram shows the that memory allocated in physical memory is not contiguous, which addresses your concern. The link posted in my first post is the code I am using to use AWE. As I mentioned, the only difference is that I'm using LoadLibrary to access the allocation and mapping functions. This link discusses AWE in more detail:
http://msdn.microsoft.com/en-us/library/aa366527(VS.85).aspx
Included in description for the AWE functions in the documentation is the following: "Physical pages can reside at any physical address. You should make no assumptions about the contiguity of the physical pages."
So the hitch at this point to making this work is VirtualAlloc(). The previous function in the example, "AllocateUserPhysicalPages()" works fine.
|
|
|
|
|
OK, I haven't thought this through yet, however I have one more suggestion:
put your code in a loop, i.e. try allocating the largest you can get, display the size (and address), do not release it, and repeat this all over and over and over. You might be getting a number of probably decreasing chunks, and the sum of those sizes (and maybe addresses) could tell you something interesting.
|
|
|
|
|
VirtualAlloc never allocate over 2GB in 32bit windows without /3GB option.
In some ordinary OS settings situation, VirtualAlloc usually returns under 1.5GB space for user land memory.
And AWE is for use of physical memory over physical 2GB boundary with /pae boot option.
If you want continuous virtual memory space over 2GB, you must use 64bit windows.
With /pae boot option, msdn document says VirtualAlloc can use over 4GB physical memory, but it would not so ordinary 32bit windows especially xp.
Because microsoft dose not support over 4GB physical memory on 32bit xp.
|
|
|
|
|
You're not allocating memory with that call to VirtualAlloc, you're allocating address space. There's only 2Gb of that per application [1] so the fact that you can't allocate more than ~1Gb in one fell swoop isn't surprising.
To be honest if you really need oodles of contiguous memory (i.e. more than 1Gb) then using a 32 bit OS is probably the wrong way to go - try a 64 bit OS and compiler then you won't have to muck around with low level stuff like this.
Cheers,
Ash
[1] Pedants please note the following exclusions: address space available to user mode code, Win32 only without /3Gb switch in boot.ini
|
|
|
|
|
|
|
You should not have removed you original message.
Your solution is worthless without knowing what the original problem was.
Watched code never compiles.
|
|
|
|
|
Does the C++ standard say anything about which side of the assignment operator is executed first? For example,
int j[1];
int i = 0;
j[i++] = i; Will j[0] be 0 or 1 after this block of code executes? Is this per the C++ standard, or is the result of this code compiler-dependent? In general, what rules govern the order of code execution like this? Is it operator associativity (assignment is right-to-left associative, so j[0] = 0), or operator precedence (post-increment and operator[] both have higher precedence than assignment, so j[0] = 1)? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
You get j[0] = 0 ; the postfix increment is meant as "use before increment" and it produce the same result than the statements below:
j[i] = i;
i = i + 1;
You can try the following:
int j[1];
int i = 0;
j[i] = j++;
This again will produce j[0] = 0 .
The answer to your question is: the increment is applied after the whole statement has been processed, like as you wrote the same statement without the postfix increment (i.e. j[i] = i ) and then another statement with only the increment (i.e. i = i + 1 ).
|
|
|
|
|