0

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

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by WaltP
1

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;
Votes + Comments
PERFECT
0

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

0

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:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.