|
mayur8u wrote: But i'm looking for a const string conversion to CByteArray.
Are you talking about std::string?
mayur8u wrote: Even if i use the CString conversion to CByteArray, is there any inbuilt methods rather than using the for loop.
Yes, you may use CByteArray methods SetSize and Getdata to copy the string content into the array buffer.
CString str = _T("Hi");
CByteArray arr;
int iSize = (str.GetLength()+1) * sizeof(TCHAR)
arr.SetSize(iSize);
const BYTE * pByte = (const BYTE *) (LPCTSTR) str;
CopyMemory( arr.GetData(), pByte, iSize);
As usual, the test is up to you.
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]
|
|
|
|
|
Ya! i'm talking about converting from std::string to CByteArray.
If there is no solution then i might have to go to CString. (Last option)
|
|
|
|
|
std::string str("Hi");
int iLen = str.length();
CByteArray arr;
arr.SetSize(iLen);
CopyMemory( arr.GetData(), str.c_str(), iLen);
Please note, the above code is not adding the null terminator at the tail of the array.
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]
|
|
|
|
|
How about the CByteArray to std:string?
|
|
|
|
|
Hi,
I'm able to convert const string& to CByteArray using the
memcpy(byteArr.GetData(), source.c_str(), source.length());
Does converting back the CByteArray to const string& work the same way using memcpy?
Regards,
Mayur M
|
|
|
|
|
char str[] = "abcdef";
int iSize = strlen(str);
BYTE * pByte = (BYTE *) str;
CByteArray arr;
for (int i = 0; i < iSize; i++)
{
arr.Add(pByte[i]);
}
the loop is must use.
|
|
|
|
|
I have a code written as:-
#include<string>
#include <iostream>
#include <iomanip>
using namespace std;
// This class Package is the base class for two other classes, TwoDayPackage and OverNightPackage.//
class Package // begins class Package
{
public:
Package(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0); // constructor
// set and get functions for sender
void setSendName(const string &);
string getSendName() const;
void setSendAdd(const string &);
string getSendAdd() const;
void setSendCity(const string &);
string getSendCity() const;
void setSendSt(const string &);
string getSendSt() const;
void setSendZip(const string &);
string getSendZip() const;
// set and get functions for recipient
void setRecName(const string &);
string getRecName() const;
void setRecAdd(const string &);
string getRecAdd() const;
void setRecipientCity(const string &);
string getRecipientCity() const;
void setRecSt(const string &);
string getRecSt() const;
void setRecZip(const string &);
string getRecZip() const;
void setWt(double);
double getWt() const;
void setShip(double);
double Package::getShip() const
{
return shipCost;
}
double Package::CalCost() const
{
return (wt*shipCost);
}
private:
string sendName;
string sendAdd;
string sendCity;
string sendState;
string sendZip;
string recName;
string recAdd;
string recCity;
string recState;
string recZip;
double wt;
double shipCost;
};
Package::Package(const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szipcode, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzipcode, double wt, double shipCost)
{
sendName = sname;
sendAdd = saddress;
sendCity = scity;
sendState = sstate;
sendZip = szipcode;
recName = rname;
recAdd = raddress;
recCity = rcity;
recState = rstate;
recZip = rzipcode;
setWt(wt);
setShip(shipCost);
}
void Package::setSendName(const string &sname)
{
sendName = sname;
}
string Package::getSendName() const
{
return sendName;
}
void Package::setSendAdd(const string &saddress)
{
sendAdd = saddress;
}
string Package::getSendAdd() const
{
return sendAdd;
}
void Package::setSendCity(const string &scity)
{
sendCity = scity;
}
string Package::getSendCity() const
{
return sendCity;
}
void Package::setSendSt(const string &sstate)
{
sendState = sstate;
}
string Package::getSendSt() const
{
return sendState;
}
void Package::setSendZip(const string &szipcode)
{
sendZip = szipcode;
}
string Package::getSendZip() const
{
return sendZip;
}
void Package::setRecName(const string &rname)
{
recName = rname;
}
string Package::getRecName() const
{
return recName;
}
void Package::setRecAdd(const string &raddress)
{
recAdd = raddress;
}
string Package::getRecAdd() const
{
return recAdd;
}
void Package::setRecipientCity(const string &rcity)
{
recCity = rcity;
}
string Package::getRecipientCity() const
{
return recCity;
}
void Package::setRecSt(const string &rstate)
{
recState = rstate;
}
string Package::getRecSt() const
{
return recState;
}
void Package::setRecZip(const string &rzipcode)
{
recZip = rzipcode;
}
string Package::getRecZip() const
{
return recZip;
}
void Package::setWt(double wt)
{
wt = (wt < 0.0 ) ? 0.0 : wt;
}
double Package::getWt() const
{
return wt;
}
void Package::setShip(double shipCost)
{
shipCost = ( shipCost < 0.0) ? 0.0 : shipCost;
}
// This class TwoDayPackage is the first derived class from class Package.//
class TDP : public Package
{
public:
TDP(const string &, const string &, const string &, const string &, const string &, const string &,
const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); // constructor
void setFlatFee(double);
double getFlatFee() const;
double CalCost() const;
private:
double flatFee;
};
// This class OverNightPackage is the second derived class from class Package.//
class ONP : public Package
{
public:
ONP(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double=0.0, double=0.0, double=0.0); // constructor
void setFee(double);
double getFee() const;
double CalCost() const;
private:
double fee;
};
// This is the test program.//
int main()
{
ONP box("name", "123 this Street", "boston", "ma", "12345", "receiver", "123 that street", "medford", "ma", "25341", 10.00, 1.50, .85);
TDP parcel("name2", "123 1st Street", "orlando", "fl", "56474", "receiver2", "833 2nd Street", "miami", "fl", "88472", 15.00, 1.05, 5.00);
cout << fixed << setprecision(2);
cout << "To ship a box with overnight delivery\n";
cout << "The sender " << box.getSendName()<< "\n";
cout << " " << box.getSendAdd() << "\n";
cout << " " << box.getSendCity() << " " << box.getSendSt() << " " << box.getSendZip() << "\n";
cout << "The recipient " << box.getRecName()<< "\n";
cout << " " << box.getRecAdd() << "\n";
cout << " " << box.getRecipientCity() << " " << box.getRecSt() << " " << box.getRecZip() << "\n";
cout << "The cost is $ " <<box.CalCost() << "\n";
cout << "\n\n";
cout << "To ship a parcel with 2 day delivery\n";
cout << "The sender " << parcel.getSendName()<< "\n";
cout << " " << parcel.getSendAdd() << "\n";
cout << " " << parcel.getSendCity() << " " << parcel.getSendSt() << " " << parcel.getSendZip() << "\n";
cout << "The recipient " << parcel.getRecName()<< "\n";
cout << " " << parcel.getRecAdd() << "\n";
cout << " " << parcel.getRecipientCity() << " " << parcel.getRecSt() << " " << parcel.getRecZip() << "\n";
cout << "The cost is $ "<<parcel.CalCost() << "\n";
system("pause");
return 0;
}
The calcost function needs some change as it is the source of error.Somebody help.
modified on Monday, February 16, 2009 12:15 PM
|
|
|
|
|
Keep your question concise! No-one will want to read all of that to answer your question!
Regards,
--Perspx
"A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year." -Andrew Tanenbaum
"Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer." -Fred Brooks
|
|
|
|
|
Didn't this come out of Deitel's "C++: How to Program" book? Is this your assignment?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes but it is from exercise.Can you tell me where solutions are available.it would help me a lot
|
|
|
|
|
tksrules wrote: Can you tell me where solutions are available.
In the classroom/lab. Does the instructor offer a Q&A session either at the start or near the end of class?
tksrules wrote: it would help me a lot
Quite the opposite, actually. You can't post a big wad of code on some Internet forum and ask someone to help you figure it out. I guess you can, but then you haven't been helped. At a minimum, you need to isolate the problem down to a small handful of statements (the actual number varies, but if it's more than a dozen, that's likely too many). Everything else is irrelevant and only acts as a hinderance.
Instead of trying to work through 200 lines of code, why not start with a smaller project, get it working, and then add to it until the problem shows itself?
This forum is frequented by a lot of sharp people that will gladly help you, but they aren't going to do it for you. You might look real closely at Package::setWt() and Package::setShip() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i am solving assignment myself...i will take ur advice.
|
|
|
|
|
We (Italians) say 'tana!' in such circumstances...
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]
|
|
|
|
|
Which translates to what in English?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Well, I'll try...
When playing hide-and-seek, if you eventually discover your opponent hiding place then say 'tana!' and win the game.
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]
|
|
|
|
|
So, that translates to "gotcha" in English. Hand in the cookie jar?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Yes, 'hand in the cookie jar' looks appropriate.
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 all,
if any body having the code regading encryption and decryption functions that will work in the sunOS please send it to me.
regatrds
suresh
modified on Monday, February 16, 2009 7:59 AM
|
|
|
|
|
Do you know about Google [^]?
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]
|
|
|
|
|
|
Stuart Dootson wrote: SunOS was obsoleted many, many, MANY years ago[^]...
He could be right as well. We still write code for SunOS (Indian Railways use it).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I thought the company I work for had out of date IT - we still use Windows 2000 and Office 2000
But still using SunOS? Last time I saw that was around 2000 - our team had a SunOS box with Oracle as our development DB server.
But the first time I saw SunOS was in the late 80s at university, when we had one of these[^] shared between around 100 students. Now, that was slow - even though we were all using VT100 terminals...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: I thought the company I work for had out of date IT - we still use Windows 2000 and Office 2000 Dead
I'm fortunate on that. At work place, we have pretty good configuration: NVidia Quadro, Intel Xeon (2 processors, 2cores per procesor) clocking at 3+ GHz, 4 Gigs of RAM and Windows XP some running 32 bit, some running 64 bit, etc.,
One of our earlier projects were for Indian railways and they are *still* running SunOS. Not long ago do I remember debugging on their premises, on an AIX machine with VI editor (not a dumb terminal, semi-intelligent, has a 200 MB hard disk drive) and the code runs on a SunOS server machine. Not the happiest thing to do if you ask me. We still receive support requests that sometimes involve writing code for SunOS, which fortunately some of my juniors take care of.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Windows 2000 is OK to program for - the main issue is that most modern development tools tend to have XP as a minimum.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello All,
Iam using CTreeCtrl method to add items in a tree.Actually i create two root nodes using GetRootNode()method.I add both root nodes properly in the tree,But what's my problem is i need to add child nodes in appropriate parent(root)nodes at runtime.But,all the child nodes adding in the first parent(root)node only.once i use deleteallitems()method and redraw the tree only child nodes are added in appropriate parent(root)nodes.Without using DeleteAllItems() i need to add the child nodes in a appropriate parent(root)node.
please anybody help me.
Thanks in advance,
Regards,
bhanu.
|
|
|
|
|