Im trying to open a file. The user enters the name of the file they want to open example

string fname;
string pick;

cin>>fname;
cout<<"Do you want to open the file?";
cin>>pick;
if(pick=="yes")
system("wmplayer.exe fname");
else
cout<<"Thanks for your time;

Can someone show me how the replace the fname above with the name the user entered or a way to tell the system command that thats the file i want to open. Lets say fname is sound.mp3

Recommended Answers

All 3 Replies

concatenate the two strings before calling system

string fname;
string pick;

cin>>fname;
cout<<"Do you want to open the file?";
cin>>pick;
if(pick=="yes")
{
    string command;
    command = "umplayer.exe " + fname;
    system(command.c_str());
}
else
cout<<"Thanks for your time;
commented: PERFECT +2

concatenate the two strings before calling system

string fname;
string pick;

cin>>fname;
cout<<"Do you want to open the file?";
cin>>pick;
if(pick=="yes")
{
    string command;
    command = "umplayer.exe " + fname;
    system(command.c_str());
}
else
cout<<"Thanks for your time;

PERFECT thanks a million

concatenate the two strings before calling system

PERFECT thanks a million

Gee, what was it I said? Oh yeah,

Concatenate "C:\\wmplayer.exe " and fname into a char* and use that variable.

:icon_rolleyes:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.