|
What do you mean with 'better'?
If you mean 'more good looking', then I suppose your code becomes 'ugly' only if some of your // do someting for ... is long (I mean, switch , in my opinion, isn't much better than the if -chain).
A completely different approach would be transforming the // do something for .. pieces of code into functions (or function objects) and then use a std::map to map the strings to the function pointers (or function objects).
Veni, vidi, vici.
|
|
|
|
|
1. for each string in your list, register a domain name: A.com, B.com, C.com, etc..
2. on each site, install a web service that will return the code to be used in the "// do something for A" and "// do something for B", sections.
3. your code then calls out to the web service hosted at: "http://" + string + ".com"
4. it will receive the code it needs to execute
code = getCodeFrom("http://" + string + ".com");
exec(code);
it's up to you which language you use for the code, but you will obviously need an interpreter of some kind.
|
|
|
|
|
I'll try it.
Veni, vidi, vici.
|
|
|
|
|
+5. Absolute professional approach, however you forgot to mention the use of some useful frameworks/middlewares.
|
|
|
|
|
That would freak out my code-reviewer !!!
Watched code never compiles.
|
|
|
|
|
Can you reduce the scope of your problem space?
By that I mean: The broad example presumes that the input can be essentially anything.
Change that such that the input can begin with only certain strings or must contain certain keywords. Then you can divide the code up into different sections depending on how the input string can be grouped.
Thanks for your time
|
|
|
|
|
Hi all,
How can i run the bat file using SghellExecute.I am trying with the below code.
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW);
Note : Test.bat file path is "C:\Test.bat"
I am unable to run the bat file.Am i doing anything wrong..??
But when i manually click on Test.bat with the mouse,The bat file executes fine.
Thanks in Advance
Manju
|
|
|
|
|
Try the following.
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C C:\\Test.bat"),0,SW_SHOW);
I suspect that when cmd.exe is run, it is unable to find the file Test.bat.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Instead of
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/C Test.bat"),0,SW_SHOW);
use either this:
ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("/C C:\\Test.bat"), NULL, SW_SHOW);
or this:
ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("/C Test.bat"), _T("C:\\"), SW_SHOW);
Note that the two solutions are not equivalent. In the second solution the current directory of your batch file will be C:\ while in the first case cmd.exe will inherit the current directory of the program from which you call ShellExecute() .
|
|
|
|
|
Hi all,
I am trying to write one string to a file.But i am getting only one character
saved in my Text.txt file.Output text file contains only "a" in it.
How can i get whole string saved in my text file.
Here is the code i am trying:
FILE *fptr;
CString Text;
Text = "asdasdasdasd";
fptr = fopen("D:\\Test.txt","w+");
if(fptr== NULL)
exit(1);
fprintf(fptr ,"%s",Text);
fclose(fptr);
If i write it as ""asdasdasdasd"" instead of passing the CString,it writes in the text file
fprintf(fptr ,"%s",""asdasdasdasd"");
Can anyone help me,where i am going wrong.
Thanks
Manju
|
|
|
|
|
I suspect your CString may be defaulting to Unicode (check your project settings), so it appears as though you have only written a single character. Try using CStringA and see what happens.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I suspect you are right.
Veni, vidi, vici.
|
|
|
|
|
No, I think pasztorpisti is right, the string needs to be cast to LPCTSTR to get the content.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Now I'm quite confident you are right.
Veni, vidi, vici.
|
|
|
|
|
I hope your confidence is not misplaced.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
The Text parameter you pass to fprintf() is a CString object, and and the %s format specifier expects a (const char*) or (char*) there. Instead of this you are pushing the whole CString object to the stack and the first 4 bytes of that CString instance are used as a (const char*). You have to convert the CString to either (const char*) or (char*) before using it with fprintf() . A more strict compiler like g++ would warn you about passing a non-pod object to a vararg function.
|
|
|
|
|
Are you building your project with "Use Unicode Character Set" or "Use Multi-Byte Character Set" character set. Change it to "Not Set"
Other alternative would be to use string instead of CString.
or like this with the above options set:
FILE *fptr;
CString Text;
Text = "asdasdasdasd";
fptr = _wfopen (_T("D:\\Test.txt"),_T("w+"));
if(fptr== NULL)
exit(1);
fwprintf(fptr,_T("%s"),Text);
fclose(fptr);
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
|
I'm experimenting with creating my first COM class. I named the class ComClass when I used the wizard to add a simple ATL object to my MFC DLL that has ATL support.
The problem is that the generated header file for my class has this line in it:
#include "ComClass_i.h"
The named file does not exist in my project directory. I assume it was supposed to be generated when I created the class.
What did I do wrong?
SOLUTION:
It turns out that the missing file gets automatically generated when you build the project! So all I had to do was build it, and the file was created.
The difficult we do right away...
...the impossible takes slightly longer.
modified 23-Aug-12 14:07pm.
|
|
|
|
|
Hi,
I just got an error converting a VS 2008 project to 2010
"Can not view XML input using XSL style sheet Please correct the error and click the
refresh button or try again Later
Can anyone help
Thanks
|
|
|
|
|
And how is this a C++ question? Please make an effort to use the correct forum for your questions.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I looked around and couldn't find an appropriate forum
|
|
|
|
|
You couldn't find this one[^]?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Sorry u right I was looking in the wrong place
Thanks
|
|
|
|
|
Why are all posts expanded now by default?
It is so ugly and I can see nothing except “HOW TO ANSWER A QUESTION”.
Could you change it to previous style? Or I have to leave.
.
|
|
|
|