|
If you entered 1,000.00 in code, it would result in a compiler error. If you entered the same thing in a masked edit control, it should be acceptable. It appears to me mtucker6784 is working with user input of some sort.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I assumed a simple fscan type operation since he said he was a beginer and it was a 5 line program.
|
|
|
|
|
Here is what I'm looking at
"
#include <iostream>
#include <windows.h>
using namespace std;
float ipad;
void main() {
cout << "What is my ip address?\n";
cin >> ipad;
cout << "I typed in\n";
cout << " " << ipad;
}
"
I'm not sure what an fscan function is but I'll look around the site and see how I can use it. I'm using the ip address situation as an example of having more than one decimal. In reality, I'm just trying to understand how this all will work. Thanks in advance, --Mike
|
|
|
|
|
mtucker6784 wrote: I'm not sure what an fscan function is
It's called fscanf() . It allows reading formatted data from a stream. To read formatted data from the keyboard, you could use scanf() , like:
char a[4], b[4], c[4], d[4];
scanf("%[0-9].%[0-9].%[0-9].%[0-9]", a, b, c, d); I would not recommend this, however, as there is no way to check for bad input.
SInce IP addresses are strings, even though they happen to contain dots, what you are using will work if you change ipad to a string type rather than a float .
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I have an edit box which people text many lines of text into.
Lets say the text is:
Danielle Brina
Suite 1
I want to get each line of the edit box, so I have:
int i, nLineCount = pmyEdit->GetLineCount();
CString strText, strLine;
for (i=0;i < nLineCount;i++)
{
// length of line i:
int len = pmyEdit->LineLength(pmyEdit->LineIndex(i));
pmyEdit->GetLine(i, strText.GetBuffer(len), len);
strText.ReleaseBuffer(len);
}
But what happens is the first line looks like:
Danielle Brina
and the 2nd line looks like
Suite 1e Brina
which is a combination of the two. I tried adding strText.Empty();
as well as other commands, but I cant get the two lines to stop
blurring. Anyone see an obvious solution?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
GetLine does not append a NULL terminator to the end of the string, so you have to insert a NULL at the end of the line yourself.
int len = pmyEdit->LineLength(pmyEdit->LineIndex(i));
LPTSTR Buffer = strText.GetBuffer(len + 1);
pmyEdit->GetLine(i, Buffer, len);
Buffer[len] = NULL;
strText.ReleaseBuffer();
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Hi Friend,
I want to create a link list using STL. I am doing the following
-----------------.h file---------------
struct CNode
{
long x;
_bstr_t b;
_bstr_t c;
};
class A
{
...
typedef std::list<CNode* > SEC_MSG_DATA;
SEC_MSG_DATA node;
...
}
--------------------------------------------------
I am trying to acces the member of the structure CNode through the object pointer of class A (pA->node.x) however i am getting the error message
<x is not a member of 'list<struct CNode *,class std::allocator<struct CNode *> >
Can you please help me.
Thanks
-- modified at 11:39 Friday 28th October, 2005
|
|
|
|
|
please edit your post, put the code between <pre></pre> tags, and use the buttons "<" and ">" at the bottom of the edit field to let us see what you put in your list.
moreover, please give us the entiere error message and the related code that is crashing.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
how do you access the node please (give me some real code that's accessing it !)
consider using iterators...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
using iterator i can get the store data however i have to fill the member of structure first.I have made some change in the code above.
|
|
|
|
|
why not you create a vector of your Class type?
for example,
class YourClass
{
public :
int i;
int a;
}
YourClass mObj;
vector<yourclass>vec1;
mObj.a=100;
mObj.i=45;
vec1.push_back(mObj);// consider this object as a Node.
and even you can define your own functions in the class to navigate or search a node. will this work?
--[v]--
|
|
|
|
|
If you see i am doing the same thing instead of using class i am using structure to store in list. Only problem i am facing i am not able to access the member of that structure.
|
|
|
|
|
thatz y i'm asking u to consider using a class. i'm still not sure what'd be wrong. but i dont find any problem using the below code.
for(i=0;i<vec1.size();i++)
{
cout<<"\n";
cout<<vec1[i].a;
}
--[v]--
|
|
|
|
|
you cannot access members of a std::list like you would do in a normal C/C++ linked list.
you need to create an iterator to access each item in the list :
( untested and unverified code ... )
<br />
typedef std::list < CNode* > SEC_MSG_DATA;<br />
...<br />
<br />
SEC_MSG_DATA::iterator it = node.begin();<br />
CNode* pNode = *it;<br />
to traverse the list, you can do something like :
<br />
SEC_MSG_DATA::iterator it = node.begin();<br />
while ( it != node.end() )<br />
{<br />
CNode* pNode = *it;<br />
<br />
++it;<br />
}<br />
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
yeah we can. I just resolved the problem however thanks to all for showing interest in my issue.
|
|
|
|
|
Hello people,
I am trying to setup an VC++ and VB application on my machine, which is visual stuido.net 2003 enterprise edition. When I install the application I am getting the following error. Debug Assertion Failed "File: Ctlreg.cpp Line:520". Anybody have idea about this kind of error and how to resolve this? I just searched this file on my machine and found two versions. Is this related to this?? If anybody having clue suggest some solution.
Regards,
Satya
|
|
|
|
|
I want to show my Internet Explorer toolbar in Internet Explorer programatically (meaning that after installation the user does not have to access the "View > Toolbars >" in order to display the toolbar). I remember I read somewhere about how you can acomplish this, but cannot find the link anymore.
Anyone care to share some light on this matter?
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
hi,
I am writing a C++ App for for windows, It is a very time critical application and I seem to have a problem when paging is necessary (that was a long debug session).
The server running the program does have any memory problems, it runs on 2GB of RAM and has no other job except that program.
I am using WIN32 API HeapCreate and HeapAlloc functions.
Is there any way to keep the Heap (a few MB) in the physical memory?
|
|
|
|
|
ja1001 wrote: Is there any way to keep the Heap (a few MB) in the physical memory?
Back when we used to use GlobalAlloc() , we could specify the GMEM_FIXED flag. I only use new /delete these days, and keeping memory from being swapped to disk is not a concern.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
ja1001 wrote: It is a very time critical application
Do you need to have a real-time behaviour ? If yes, you will run into troubles because windows is not a real-time operating system ! The CPU time allocated to your program will be shared with the other running processes. You cannot garanty precisions under 10 or 20 msec (depending on a lot of factors).
|
|
|
|
|
|
VirtualLock
The VirtualLock function locks the specified region of the process's virtual address space into physical memory, ensuring that subsequent access to the region will not incur a page fault.
BOOL VirtualLock(
LPVOID lpAddress,
SIZE_T dwSize
);
Locking pages into memory may degrade the performance of the system by reducing the available RAM and forcing the system to swap out other critical pages to the paging file. Each version of Windows has a limit on the maximum number of pages a process can lock. This limit is intentionally small to avoid severe performance degradation. Applications that need to lock larger numbers of pages must first call the SetProcessWorkingSetSize function to increase their minimum and maximum working set sizes. The maximum number of pages that a process can lock is equal to the number of pages in its minimum working set minus a small overhead.
Pages that a process has locked remain in physical memory until the process unlocks them or terminates.
To unlock a region of locked pages, use the VirtualUnlock function. Locked pages are automatically unlocked when the process terminates.
If memory was allocated with HeapAlloc, you can use VirtualQueryEx to get an appropriate start address.
|
|
|
|
|
This is what I did and the VirtualQueryEX() returend 0 and nothing in the struct.
What am I doing wrong?
void main(int argc, char *argv[])<br />
{<br />
DWORD dwMin, dwMax;<br />
HANDLE hProcess;<br />
_MEMORY_BASIC_INFORMATION MemInfo; <br />
<br />
HANDLE hHeap = HeapCreate(NULL, 1024 * 1024 *20, 1024 * 1024 * 30);<br />
<br />
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());<br />
if (hProcess == INVALID_HANDLE_VALUE)<br />
{<br />
printf( "OpenProcess failed (%d)\n", GetLastError() );<br />
return;<br />
}<br />
if (SetProcessWorkingSetSize(GetCurrentProcess(), 1024 * 1024 *20, 1024 * 1024 *30) != 0)<br />
{<br />
printf("Process Size Set!\n");<br />
}<br />
else<br />
{<br />
printf("Error in seting the Process Size!\n");<br />
}<br />
printf("%d\n",VirtualQueryEx(hProcess, hHeap, &MemInfo , 1024 * 1024 *20));<br />
printf("\n MemoryRegionSize: %d\n", MemInfo.RegionSize);<br />
<br />
if (VirtualLock(MemInfo.BaseAddress, MemInfo.RegionSize) != 0)<br />
{<br />
printf("Virtual Lock Success!!!\n");<br />
}<br />
else<br />
{<br />
printf("Virtual Lock Failed!!!\n");<br />
} <br />
CloseHandle(hProcess);<br />
}
HELP?!?!
|
|
|
|
|
The heap create makes a 'region' of memory available thorugh the API. To determine where the memory is actually located, you must use the pointer returned from HeapAlloc. Allocate a small block of memory, say 8 bytes, using HeapAlloc and then pass that pointer into the VirtualQueryEx function.
LPVOID lpMyMem = HeapAlloc(hHeap, 0, 8);
Also, VirtualQueryEx size is sizeof() not the size of the memory you think you got.
VirtualQueryEx( hProcess, lpMyMem, &MemInfo, sizeof(MemInfo) );
This should let you know how much memory the Heap has comitted and reserved, and its true starting address, so you can call VirtualLock.
|
|
|
|