|
Is it possible to get the selected item of a combo box while navigating the drop list?
i.e., getting the selected items value and text?
Is there a Windows message that handles the mouse selection of each item in combo drop list?
This is when the combo box drop down is active.
|
|
|
|
|
|
Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......
Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore
What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...
Sam Worthington ... Jake Sully
Zoe Saldana ... Neytiri
Sigourney Weaver ... Dr. Grace Augustine
Stephen Lang ... Colonel Miles Quaritch
Joel Moore ... Norm Spellman (as Joel David Moore)
.........(and so on)
This is my coding..
string templine ;
string line;
ifstream myfile ("test");
while (getline (myfile,templine) )
line.append(templine);
char str [] = line ;
char delims[] = "as";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( result );
result = strtok( NULL, delims );
}
I keep getting the error saying ...
editmain.cpp.98:error: initializer fails to determine size of 'str' modified on Monday, February 8, 2010 1:41 PM
|
|
|
|
|
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
|
|
|
|