I need help to format a drive where the user enters the letter that needs to be formmatted and then it formats that drive. Need help desperately.
Have tried using variables here is my code:
#include <iostream>
int main() {
std::cout << "Welcome to Magic Memory Stick Creator Version 1.5. Please follow all instructions on screen." << std::endl;
std::cout << "Please enter the drive in which your psp is plugged in." << std::endl;
char iDrive;
std::cin >> iDrive;
std::cout << "The drive " << iDrive << " will now be formatted." << std::endl;
system("format iDrive:");
return 0;
}
"format iDrive:" is a string literal (ie, constant). You are expecting that the compiler will substitute the contents of your iDrive variable in place of the iDrive in the string literal. This does not happen.
You need to build the string yourself. For example:
Well I all but did fix it for you. The only other step you need is to extract the (const) char* from the string because system() expects a const char*.
int main() {
std::cout << "Welcome to Magic Memory Stick Creator Version 1.5. Please follow all instructions on screen." << std::endl;
std::cout << "Please plug in your PSP and put it onto USB mode." << std::endl;
std::cout << "Please enter the drive in which your psp is plugged in." << std::endl;
std::string dir;
std::cin >> dir;
std::string ; command = ( "dir " ) + ' ' + ( "dir" );
;system(command.c_str() );
return 0;
}
I keep getting these errors:
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\magic memory stick creator\magic memory stick creator\main.cpp(10) : error C2065: 'command' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\magic memory stick creator\magic memory stick creator\main.cpp(10) : error C2110: '+' : cannot add two pointers
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\magic memory stick creator\magic memory stick creator\main.cpp(11) : error C2065: 'command' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\magic memory stick creator\magic memory stick creator\main.cpp(11) : error C2228: left of '.c_str' must have class/struct/union
I don't generally just write the code for the person; that does not teach the person anything, and the programming profession is all about continual education.
It sounds like it couldn't find the format.exe / format.com executable.
All you have to do to my original code was replace "dir " with "format ".
Once the user has input the drive letter, we can check the last character position to see if it is a colon.
If the user has forgotton the colon we can add one.
#include <iostream>
#include <string>
usingnamespace std;
int main() {
std::cout << "Welcome to Magic Memory Stick Creator Version 1.5. Please follow all instructions on screen." << std::endl;
std::cout << "Please plug in your PSP and put it onto USB mode." << std::endl;
std::cout << "Please enter the drive in which your psp is plugged in." << std::endl;
std::string format;
std::cin >> format;
//Check if user has remembered to add the colon to the drive letter
if( format.at (format.length()-1) != ':' )
{
//if not we add it ourselves
format += ':';
}
std::string command = "format " + format;
system( command.c_str() );
system("pause");
return 0;
}