|
This is inherently flawed. You have no way to distinguish between "as" as a delimiter and "as" as 2 characters in a name.
As far as your error message, since str is an array of char, you have to specify how big it is to be. You don't.
Why are you mixing std::string and char arrays?
Since you are using std::string, I would suggest you use it and not char arrays at this point. After you have some things more figured out, you could learn how to use char arrays. They are more demanding to get right.
|
|
|
|
|
Cannot assign string object to a char array as follows:
char str [] = line;
May be you can do as follows to correctly use tokenizer function:
char* str = _strdup(line.c_str);
char delims[] = "as";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL )
{
printf( result );
result = strtok( NULL, delims );
}
free(str);
|
|
|
|
|
It still won't work; strtok() will break on any 'a' or 's'. He will need to use strstr() , or similar.MVP 2010 - are they mad?
|
|
|
|
|
That is true. I thought he needs to break on any 'a' or 's'
|
|
|
|
|
Goodness knows why anyone would choose alphabetics as separators; I am sure none of the strtok() samples around the net suggest it.MVP 2010 - are they mad?
|
|
|
|
|
Yes you are right!!! No samples around the net suggests that.
|
|
|
|
|
I am having problems with File I/O in C++. What I am trying to make is a save game function. I am using the following code.
ofstream outputFile("bin/name.txt");
ifstream inputFile;
outputFile << name;
outputFile.close();
inputFile.open("bin/name.txt");
I am using Dev-C++, and it doesn't encounter any errors. However, it doesn't create the file (name.txt) either. I am using the same code for various other variables as well.Whoever said nothing is impossible never tried to slam a revolving door.
modified on Monday, February 8, 2010 12:17 PM
|
|
|
|
|
what type of variable "name" is?
The following code generates name.txt in my project directory. and dumps the string in file.
ofstream outputFile("name.txt");
ifstream inputFile;
string name = "ABCD";
outputFile << name.c_str();
outputFile.close();
HTH
|
|
|
|
|
Hi,
I've created a custom control where I want to be able to change the colour of the control dependent on the background colour of my dialog, i.e. if the user has customised their dialog I would like to set my control to the same colour.
Is it possible to determine this colour at runtime?
Also, is there a list of predefined colours available, e.g. the default colour of a dialog, and if so where are they defined?
TIA
Tony
|
|
|
|
|
maycockt wrote: Is it possible to determine this colour at runtime?
See Window Background[^] for how this information is held.
maycockt wrote: is there a list of predefined colours available
See GetSysColor()[^].MVP 2010 - are they mad?
|
|
|
|
|
Use the GetClassLongPtr[^] function with the handle of the dialog and GCLP_HBRBACKGROUND as the index.
|
|
|
|
|
May be you can call the following from the custom control:
COLORREF rgb = GetParent()->GetDC()->GetPixel(0, 0);
This may not work if the point (0, 0) on the parent is overlapped by the control.
|
|
|
|
|
Hi
Suppose I have a class like:
Class CMyTestClass {....}
I save this name in a string like:
char* ClassString = "CMyTestClass"
How can I instance this by using this string?
CMyTestClass* pmyClass = new ClassString ????????
Thanks,
|
|
|
|
|
It's possible, but your class should derive from CObject in MFC environment. CRuntimeClass::FromName method could be used to accomplish this task.See here for details. Life is a stage and we are all actors!
|
|
|
|
|
But my class is not derived from "CObject".
How can I do that?
Thanks
|
|
|
|
|
There's no way to do that by default. However, you could create a factory class which is responsible for creating instances of your class (as long as they all inherit from the same base class) based on their name. I suggest you google for "Factory pattern" in C++.
|
|
|
|
|
Cedric Moonen wrote: I suggest you google for "Factory pattern" in C++.
but it factory pattern, all class name should be pre-known, i think he asking for dynamically loading class object. "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
ThatsAlok but it factory pattern, all class name should be pre-known, i think he asking for dynamically loading class object.
You can't create an instance of a class that doesn't exist... Of course your classes have to be known at compile time, thus you can also populate easily your factory with the names.
Furthermore, even if you were able to create an instance of any class, what would you do with it ? You can't write any code that will use the class because you don't know which object you are manipulating (unless all the classes inherit from the same base class in which case you manipulate the base class).
|
|
|
|
|
|
Moak wrote: Okay this is the same as Cédric just posted... now you have some links
Na naah naa... you posted ur reply to wrong person!.... "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You can write a creator class which can help you create objects.
Inside the class you will need code that will check the class name and create the object for you -
static void* Creator(char* className)
{
if (strcmp(className, "CMyTestClass") == 0)
return new CMyTestClass;
else if (strcmp(className, "CMyTestClass2") == 0)
return new CMyTestClass2;
.
.
.
}
|
|
|
|
|
«_Superman_» wrote: static void* Creator(char* className){ if (strcmp(className, "CMyTestClass") == 0) return new CMyTestClass; else if (strcmp(className, "CMyTestClass2") == 0) return new CMyTestClass2; . . .}
He he he looks like Factory Pattern "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
transoft wrote: I save this name in a string like:
char* ClassString = "CMyTestClass"
yes it is possible as told by poster above me.. frankly i never do it as it will leave hacker chance to crack my application, better procedure would be to use good old polymorphism "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
This has nothing to do with "hacking". There are some cases where this is extremely useful (it depends a lot on the context of course). And your point about polymorphism has nothing to do with the question. Creating a specific instance of a class using an Id (a name for instance) using a factory pattern uses polymorphism anyway.
Here's a concrete example in which this could be useful. Suppose you have a program that is able to execute a list of operations. The user is able to create an XML file containing the information about the different operations to execute. What you would typically do is have a different nodes in your XML file (one for each operation you want to execute). And for each of these nodes, you can have parameters which are specific to the operation you want to execute. One property of the node is of course the name of the operation to execute. This way, when loading the file you get the name of your operation, delegate the creation of the operation to the factory and pass the parameters to the operation object so that it can "configure" itself from the xml information. Once your object is constructed, you can store it in a list along other operations to be executed. Of course, all the specific operation classes inherit from the same base class (which provide virtual functions like run, loadPropertiesFromXML, ...).
This is of course one simple example but there are a lot of cases where this becomes useful.
|
|
|
|
|
Hi all,
please help me to resolve error of Access is Denied.
When server is Windows server 2008 and client machine is Windows xp Professional with service pack 3.
in network window when i want to access this client machine its popup a username and password window to access.
in my code if i use RegConnectRegistry without entering username password in network window for xp client,this return a error of Access Denied.
if i use RegConnectRegistry after entering username password in network window for xp client,
than its execute,no error return but after the i want to open the registry by RegOpenKey.
now this return error access denied.
please help me what can i do.
thanks.To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|