Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 22nd, 2005, 6:53 AM   #1
Esmirna
Newbie
 
Join Date: Feb 2005
Posts: 10
Rep Power: 0 Esmirna is on a distinguished road
system(const char*)

this function in c++ works as follows -> system("c:\example.exe");
but i wish to pass a string instead of writing it -> system(myString);
where myString has paths that can be changed on running time.

how do i declare the string or what can i do to use a standar (std::string myString="hello") one in 'system' function?
Esmirna is offline   Reply With Quote
Old Feb 22nd, 2005, 7:13 AM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
It has to be a character array (or converted to one)...

#include <iostream>

int main(int argc, char *argv[]) {
    char sys[1024] = "C:\\Program Files\\Internet Explorer\\iexplore.exe "; 
    char input[256];
    std::cout << "What website would you like to view? ";
    std::cin >> input;
    strcat(sys, input);
    system(sys);
    return 0;
}
__________________

tempest is offline   Reply With Quote
Old Feb 22nd, 2005, 7:27 AM   #3
Esmirna
Newbie
 
Join Date: Feb 2005
Posts: 10
Rep Power: 0 Esmirna is on a distinguished road
thanks

thanks!!!
Esmirna is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC