954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SYSTEM

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

slygoth
Light Poster
43 posts since Feb 2011
Reputation Points: 10
Solved Threads: 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;
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

slygoth
Light Poster
43 posts since Feb 2011
Reputation Points: 10
Solved Threads: 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:

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: