![]() |
|
#1
|
|||
|
|||
Strings in system()How can I get a string to work in system()?
CPP / C++ / C Code:
currently I get the error: cannot convert `std::string' to `const char*' for argument `1' to `int system(const char*)'| |
|||
|
#2
|
||||
|
||||
Re: strings in system()CPP / C++ / C Code:
MxB |
|
#3
|
|||
|
|||
Re: strings in system()An online reference such as www.cplusplus.com can come in handy at times. For example, at times like these. The first question you can ask is "is there a standard way to do what I want to do?" Then you can go to the reference and see if there is.
Other than that, you'd probably do well to adopt some "better" coding practises right from the start. I personally find that goto/longjmp makes the code harder to follow. I'm not probably the only one, since goto is considered a Bad Thing in so many places. My recommendation would be to start without and when you know you need it, use it. Descriptive names / commenting is very important. Consider your variable 'alpha' for example. Your comment says "alpha is how many times the user wants to run it." The variable name, alpha, has absolutely no connection to the usage of the variable. More descriptive names would be 'numberOfRuns', 'timesToLoop' or similar. The same goes for 'defrag', 'anylize' (you probably meant 'analyze'?), 'numbers', 'plural'... More descriptive names could be 'defragCommand', 'analyzeCommand' or perhaps 'defrag_defrag', defrag_analyze'. The 'defrag' in the beginning separated with an underscore tries to give a hint that the variable holds the defragment command of the defrag program. Here's an idea of how I could write your program. (I wouldn't actually do it like that, I was just lazy and "fixed" a few things to look more like my ideals.) CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: strings in system()Thanks. I do know that my code is a mess and there are several better ways to do it, I'm new to c++ so i'm just using what I already know with a few things i dont.
|
|
#5
|
|||
|
|||
Re: strings in system()Quote:
There usually are, but isn't it still helpful when people try to point out the "bad" things and recommend the "good" things. |
|
#6
|
|||
|
|||
Re: strings in system()Quote:
Then you should recommend good things instead : system() is dirty and prohibited on Windows (MSDN) You must use Win32 System apis to defrag a disk. |
|
#7
|
|||
|
|||
Re: strings in system()Quote:
Actually, I have no idea how you would do it using WIN32 API, so I cannot recommend such a way. But perhaps you can show how it's done? |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| General Purpose Computer System vs. Embedded System | brookeville | Computer Software Forum - Windows | 5 | 09-Mar-2009 04:10 |
| Attempting to restore system BIOS on Dell Optiplex. | brandon1482 | Computer Hardware Forum | 3 | 27-Jun-2008 07:43 |
| Java application for a vehicle parking system | asdfg | Java Forum | 10 | 17-Jun-2007 11:58 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 19:23 |
| need help with a console menu system | BullBuchanan | C++ Forum | 6 | 20-Aug-2006 14:46 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The