|
Why don't you want anyone to see it? is your code so bad that you're embarrassed of it?
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
C:\Windows\Desktop\DataStru\main.cpp(735) : error C2100: illegal indirection
can any one tell me what this mean?
thank you
|
|
|
|
|
Seeing the faulty code could help. But it is a pointer problem, for sure
|
|
|
|
|
can anyone tell me please how do you compile and run a program that reads its input from a txt file, using the borland commmand line compiler.
or the visual C++ compiler.
thanks
|
|
|
|
|
Just push the button with the '!' on it. Or did you mean how to write such a program ?
Here is a program to read a file into a vector and then print it.
#include "stdafx.h"
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
using std::copy;
using std::vector;
using std::string;
using std::ifstream;
using std::ostream_iterator;
using std::cout;
using std::back_inserter;
using std::getline;
using std::ostringstream;
using std::istream_iterator;
int main(int argc, char* argv[])
{
string currentLine;
ifstream str("c:\\winzip.log");
if (!str.is_open())
{
cout << "It's stuffed\n";
return -1;
}
vector<string> file_contents;
copy(istream_iterator<string>(str),istream_iterator<string>(), back_inserter(file_contents));
// Now print out the results
copy(file_contents.begin(), file_contents.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
You can use this URL to go to where I posted it before, and dissected how it works.
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=105228&tid=104762#xx104770xx
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
Picture a world without war, without hate. And I can picture us attacking that world, because they would never expect it.
|
|
|
|
|
Christian Graus wrote:
Picture the daffodil. And while you do that, I'll be over here going through your stuff
I like that :rotfl:
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I've noticed that sometime upon exiting my program, it errors out with a "memory could not be read". While debugging I see that my string buffers are not reseting themselves. How can I go about clearing my buffers out so that I do not get this error. Or am I looking in the wrong place. I still am curious as to how I go about resetting my buffers each time........
Please be patient with me as I am a cobol programmer (but I understand C++) and in cobol you must initialize your buffers so that left over data does not stay put.
Thanks again
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi,
I was trying to write some string in a bitmap. Every things work fond except that I cannot change the font size. Why can I put my font in italic without any problem and I can't change my font size. This code is use in a ISAPI. Source code follow...
Thanks
Guillaume Frechette
bool Write(CString sText,int nFontType,int nFontSize,CRect cRect)
{
CClientDC dc(NULL);
CDC mdc;
CFont* pFont=NULL;
CFont* pOldFont=NULL;
CFont myFont;
LOGFONT lf;
mdc.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = mdc.SelectObject(&m_Image);
BITMAP bmp;
m_Image.GetBitmap(&bmp);
pFont = mdc.GetCurrentFont();
if(pFont){
pFont->GetLogFont(&lf);
lf.lfHeight = -MulDiv(nFontSize,
GetDeviceCaps(dc.GetSafeHdc(),LOGPIXELSY),72);
lf.lfWidth = 0;
lf.lfItalic = 1;
myFont.CreateFontIndirect(&lf);
}
else
return false;
pOldFont = mdc.SelectObject(&myFont);
mdc.DrawText(_T(sText),cRect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
dc.BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&mdc,0,0,SRCCOPY);
if(pOldFont)
mdc.SelectObject(pOldFont);
CBitmap* pNewBitmap = mdc.SelectObject(pOldBitmap);
return true;
}
|
|
|
|
|
Okay I have
char StringBuf[32400];
char StringData[10];
strncpy(StringData, StringBuf, 10);
I want to move the first 10 characters from StringBuf to StringData. Wehn I do this if I look at StringData then it have everything from StringBuf in it. How come I see the whole buff of StringBuf in a smaller character array?
Is there a better way to do this?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
If you view the contents using debugger, you'll see a lot of garbage info in the end of StringData. That's okay. But never use them. That is, never use index greater than sizeof(StringData), otherwise, you'll get those garbage data. It'll get worse if you try to write to those memory location. Your program might crash because of these illegal memory access.
|
|
|
|
|
What you want to do is:
char StringData[11];
memcpy(StringData, StringBuf, 10);
StringData[10] = '\0';
Anyway, the proper way to handle strings in C++ is to use std::string class, and not to hack with char*
I vote pro drink
|
|
|
|
|
strncpy does not insert a null. You have to do that manually. I think that is one we've all been bit by at some time. Nemanja's advice is your best alternative.
"Thank you, thank you very much" Elvis.
|
|
|
|
|
This is what I ended up doing before I tried Nemanja's advice...which by the way was the best advice.
StringBuf[11] = 0x00;
strcpy(StringData, StringBuf);
but I still got garbage in the front of the string that I wanted.
After switching to Nemanja's advice it worked great.
Thanks everyone.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
StringBuf[11] = 0x00;
strcpy(StringData, StringBuf);
but in your first post, you were doing it the other way round...
a handy mnemonic to remember is that strcpy and strncpy are layed out like an equals command:
a="hello ";
b="world";
strcpy(a,b);
and noone complain that that code doesnt work, it was an example of a point and it's not really necessary to allocate memory for a concept
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
If you must use C strings, then you should do this:
char StringBuf[32400];
memset(&StringBuf, 0, 32400); // I *think* I have the parameters in the right order
Now your string is FULL of NULL, so whatever you copy into it will be NULL terminated.
It's better to use std::string, or you can use CString if you need to convert to wide strings at any point. Then you get operator =, and the strings will resize themselves to take up as much room as you need, and no more.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I have a NT Service (usually runs on Win2K AS), that accepts requests on sockets, process them, and return a response.
We noticed, using Task Manger, that the service had nearly 50,000,000 page faults (after processing around 500,000 requests). Is this normal? If it is not, what could be the cause?
Tx
Michel
P.S.: The service operations don't seem to be affected.
|
|
|
|
|
Sounds like you need more RAM.
Jon Sagara
What about ?
|
|
|
|
|
I want to use some .Net features like GDI+ or some namespace we use in c#,
in VC++.Net,I don't know how ,any suggestion or article or..?(should I import their dll into my project?)
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
Mazdak wrote:
I want to use some .Net features like GDI+ or some namespace we use in c#,
in VC++.Net,I don't know how ,any suggestion or article or..?(should I import their dll into my project?)
Check out these articles in the .NET section.
http://www.codeproject.com/dotnet/
See Christian Graus's articles on GDI+. Those were of help in getting me started. Just don't confuse POINT with Point and RECT with Rect (That gets me every time).
|
|
|
|
|
Thanks ,It is very useful
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
Jay Beckert wrote:
See Christian Graus's articles on GDI+.
They're going to start up again now that I have a new job. Too bad it's probably a bit late now, but I'm going to do a series on image processing.
Jay Beckert wrote:
Those were of help in getting me started. Just don't confuse POINT with Point and RECT with Rect (That gets me every time).
I don't get why Color is the only class with built in conversion to the old types, if I were to write Rect, operator RECT is the third thing I would include ( after copy constructors and operator=).
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I thought you were on holiday? You're working way too hard.
Congrats again on the new job.
Jon Sagara
What about ?
|
|
|
|
|
Jon Sagara wrote:
Congrats again on the new job.
Thanks - I'm really stoked. Yes, I am on holiday, but I can't do without my dose of CP every day. Plus I'm on cable here, so I'm downloading lots of videos....
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
They're going to start up again now that I have a new job. Too bad it's probably a bit late now, but I'm going to do a series on image processing.
Nah, never to late and I'll surely be waiting for the series. I just love all the options that are available in GDI++, though I think maybe they made it to easy. Maybe I'm a control freak.
Christian Graus wrote:
I don't get why Color is the only class with built in conversion to the old types, if I were to write Rect, operator RECT is the third thing I would include ( after copy constructors and operator=).
You think? Just when I get confortable with doing it this way, i have to get used to it another way. The conversions would of been nice.
|
|
|
|
|
Jay Beckert wrote:
I just love all the options that are available in GDI++, though I think maybe they made it to easy. Maybe I'm a control freak.
I agree - I am VERY glad I learned to do all the stuff GDI+ does 'by hand' before GDI+ came along and started doing it for me.
Jay Beckert wrote:
You think? Just when I get confortable with doing it this way, i have to get used to it another way. The conversions would of been nice.
I'm sorry you misunderstood me - I am saying the same thing, I said the 'third thing' only because I would always write the copy constructor and operator= for a class before pretty much anything else. I thought if I said 'first thing' as a turn of phrase someone might ask me why
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|