|
Hi there,
This might sound silly but you just need to cast them to an int e.g.:
const char string[] = "test string";
for (int i = 0; string[i] != '\0'; ++i)
printf ("Hex 0x%x\n", (int) string[i]);
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
I think he meant converting the string representations of a hex value to the actual hex number, not the hex of any character value.
--
The Blog: Bits and Pieces
|
|
|
|
|
Oh, try this then:
const char string[] = "test string";
char hexstring[200];
hexstring[0] = '\0';
for (int i = 0; string[i] != '\0'; ++i)
sprintf (hexstring, "%s %x", hexstring, (int) string[i]);
This will create a hex list of all the characters in string .
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
...still not quite there
I'm quite sure he meant this that he has a string "D4", which without the quotes is the hex number D4. He wants to get the hex number D4, not the hex for the value of the characters 'D' or '4'. There are lots of ways to do this. I'll punch a couple out later tonight when I have time to concentrate better.
--
The Blog: Bits and Pieces
|
|
|
|
|
Can anyone plz help with the implementation of the following member functions.
1.void EmployeeDatabase::getEids(vector <int> &ids)
2.string EmployeeDatabase::getName(int employeeID)
3.double EmployeeDatabase::getShoeSize(int employeeID)
<code>
#include "EmployeeDatabase.h"
#include<vector>
using namespace std;
EmployeeDatabase::EmployeeDatabase()
{
size = 0;
}
/*void EmployeeDatabase::getEids(vector <int> &ids)
{ // Complete the code.
//int iter;
//iter = v.assign(ids, people);
for(int i = 0; i<=ids.size( ); i++)
{
}
return ids;
}
*/
/*string EmployeeDatabase::getName(int employeeID)
{// Complete the code.
// Returns the name of the Person with eid equal to employeeID.
//string TheEmployees;
}*/
double EmployeeDatabase::getShoeSize(int employeeID)
{// Complete the code.
// Returns the shoesize of the Person with eid equal to employeeID.
}
void EmployeeDatabase::makePerson(string employeeName, int employeeID, double employeeShoeSize)
{
vector <Person> m_Staff;
Person people(employeeName, employeeID, employeeShoeSize); // this assumes a class called person with this constructor signature
m_Staff.push_back(people);
}
int EmployeeDatabase::getSize()
{
return size;
}
</code>
here is the application test program I have to test the member functions.
<code>
#include "Person.h"
#include "EmployeeDatabase.h"
#include "Data.h"
#include<iostream>
#include<fstream>
using namespace std;
int main(){
EmployeeDatabase TheEmployees; // These two commands make the data in the database Data.o available
Data DB(TheEmployees); // Include these two commands at the beginning of your program, and
// then use the methods from EmployeeDatabase to get the data.
vector<int> ids;
TheEmployees.getEids(ids);
cout << "The Eid of the first employee is " << ids[0] << '\n';
cout << "The name of the first employee is " << TheEmployees.getName(ids[0]) << '\n';
cout << "The shoe size of the first employee is " << TheEmployees.getShoeSize(ids[0]) << '\n';
pause();
}
</code>
|
|
|
|
|
|
i wrote some program abt file reading and writing
in that
i declare one oftream object for writing . and i do like this
ofstream obj1;
obj1.open("......");
........;
......;//some program for writing
obj1.close();
obj1.open(".........");//another file
........;
......;//some program for wrtiing
obj1.close();
that works fine.
problem is if i declare one item for reading as writing it is not reading another file
ifstream obj2;
obj2.open("......");
........;
......;//soem progrma for readin
obj2.close();
obj1.open(".........");//it` unable to openfile
ifstream obj3;
obj3.open("......");//it`s working fine
........;
......;//some program for reading
obj3.close();
but in another program abt reading files i just declare one object for reading two files and it works fine(but that program for reading contents from existin files only)
note: in program i deal with .doc files
Regards
cnu...
-- modified at 22:22 Thursday 15th September, 2005
|
|
|
|
|
Hi everybody!
I am trying to make a graphic application in linux.In the beginning of my .cpp file, I have:
#include "matrix.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include "/home/hungnv/Tools/Rand.h"
#include "/home/hungnv/Tools/nrutil.c"
#include "/home/hungnv/Tools/nrutil.h"
#include "/home/hungnv/Tools/XRSver1.h"
#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
#ifndef _NO_TEMPLATE
typedef matrix<double> Matrix;
#else
typedef matrix Matrix;
#endif
#ifndef _NO_EXCEPTION
# define TRYBEGIN() try {
# define CATCHERROR() } catch (const STD::exception& e) { \
char Error[1000];\
sprintf(Error,"Error: %s\n",e.what());\
if(flog != NULL){fprintf(flog,Error);} }
#else
# define TRYBEGIN()
# define CATCHERROR()
#endif
when I compiled by using this command: gcc -O -o xxx xxx.cpp -L/usr/X11R6/lib -lm -lX11 -I/usr/X11R6/include
and some errors occured. It could not recognize "Matrix".
Please help me to fix this problem.
Thanks!
h
|
|
|
|
|
1. We can't see the stuff in <> because you didn't check Do not treat <'s as HTML tags
2. Why do you expect it to recognise Matrix ?
3. Why do you define STD ? The only reason I can think of is to put STD:: in front of methods, but you've put using namespace std;, which makes this redundant
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
1. Please post here instead of via email
2. Please check the box below the text entry window so that we can see the code that uses <> brackets.
3. It may help to post the actual error
4. It's obvious that you expect your includes to provide you with a matrix class. As such, posting all your code is unlikely to help, the problem is that it can't see this class, for whatever reason. Does any of these header files define a class called Matrix ? I assume the #ifdef is to differentiate between a templated and non-templated class. Are you copying this code from somewhere ? It looks like it's being written for use with crappy compilers that are no-where near standard C++. Why not just code for your compiler ?
Also, if you're including iostream.h and not iostream ( etc ), then the using namespace std stuff is useless, and if you're including iostream (etc), then you're already assuming your compiler supports namespaces.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
In the C++ STL is there a defined class/method or feature to convert/cast a structure of C-style character arrays to a structure of std::strings?
Sorry if this is in the archives but I did search before posting...
|
|
|
|
|
The string class takes a char array to it's constructor I believe. How are you wanting to do this ? There's no method to take an unknown struct and convert it to another unknown struct ( that is, from one struct the STL knows nothing about to another ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
My program is passed a pointer to a data-filled structure for which all elements are char arrays...I am looking for a way to change the type of the buffer or copy the buffer to so that I can use C++ features to work on the fields of the new buffer.
from C-style:
struct Carrays
{
char field1[50];
...
char field100[25];
} Carrays_t;
to C++ style:
struct Strings
{
std::string field1;
...
std::string field100;
}
|
|
|
|
|
Hi,
std::string implements basic_string& operator=(const E *s) .
So, you could add a conversion-constructor like this one:
struct Strings
{
Strings(const Carrays& ToCopy);
std::string field1;
...
std::string field100;
}
And use the assignment operator to initialize your new fields:
Strings::Strings(const Carrays& ToCopy)
{
field1 = ToCopy.field1;
...
field100 = ToCopy.field100;
}
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
If by structure you mean class or struct , then "no".
If by structure you mean some other structure, as a container like std::vector , then "yes", and
void TransferStrings(const wchar_t* from, size_t size, std::vector<std::wstring>& to)
{
std::copy(from, from + size, std::back_inserter(to));
} should do it.
--
The Blog: Bits and Pieces
-- modified at 5:26 Sunday 18th September, 2005
|
|
|
|
|
Hi..everyone.
Anybody can help me?????
I have problem to do my project using mfc.net. Actually i'm a student then I want to develop a project about drawing tools.So I have problem with the coding, I don't know the coding for drag and drop button.My problem situation like this I want draw a image like a car then the image will be saved in the button. If the user want to draw a car they just drag and drop the button so the car is already drawn at the screen.
Next , I want to color the car so user can choose any color that they want to use it.May I have a coding to do like that situation .Please help me, I really want a coding as soon as possible.So, if anyone can be sent me an example project for drawing tools or similar project that I was doing now.
Thank you...
allo it's me
-- modified at 5:38 Thursday 15th September, 2005
|
|
|
|
|
MFC.NET ?????
MFC is perfectly the opposite of .NET, so i doubt such a product exist !
do you mean MFC 7 instead (provided with Visual Studio .NET 2003/2005) ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
MFC is perfectly the opposite of .NET
I wouldn't exactly say that. MFC is just a UI toolkit for C++ developers. If you read Nick Kramer's blog on blogs.msdn.com, or if you go to the PDC this year, you'll note that MFC and .NET can integrate quite well.
That said, there is no managed MFC project right now, and I don't think there will be, as I see no reason for one with the new Avalon UI, as well as the existing Windows Forms toolkit.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
-- modified at 14:23 Friday 16th September, 2005
|
|
|
|
|
If you're using MFC in a .NET compiler, you have GDI+ available to you. In GDI+, you can use the DrawImage function with an Image Attributes object that can specify a colour range to make transparent. This is how you'd get an irregular bitmap and draw it onto an existing image.
GDI+ also offers matrix operations by which you can change colors in an image, you can also do flood filling, if you want.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Where I can find the GDI+ in MFC and how tu use it.
allo it's me
|
|
|
|
|
Read my articles on this site. Just search for my surname (graus), you'll find them.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
class A
{
public:
A& operator*()
{
return *this;
}
void f()
{
}
};
int main()
{
A a;
A* p = &a;
(*p).f();
}
Why the operator '*' doesn't get called, I can't even set the break point inside it!
|
|
|
|
|
overloading * operator make object of that class use that, not pointer.
Following code will make call to overloaded *
int main()
{
A p;
(*p).f();
}
|
|
|
|
|
Then what the real application of this operator?
|
|
|
|
|
As other operators. Operator overloading meant for giving more meaning to UDT's.
For example you can see any smart pointer class.
You can use object of those classes and pointer.
e.g. CComPtr<someInterface> somePtr;
somePtr->someFn();
(*somePtr).someFn();
refer http://www.codeproject.com/cpp/ismart.asp[^]
|
|
|
|