Thread: using windows system()

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Question using windows system()

    I am kinda new to C++ and I would like to know if it is possible to pass on the values of variables to the system() functions?

    example:
    Code:
    void main()
    {
        char tag[1];
    
        cin >> tag;
    
        system("attrib tag");
    }
    this one doesn't work. Its just to give an example of what I want to do... I want to pass the value stored in tag as apart of a system() argument. Is it possible? if yes, how do I do it?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to build the string to pass to system, using sprintf or stringstreams or something similar.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Is it possible? if yes, how do I do it?
    Try this.
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    int main()
    {
    	std::string tag;
    
    	std::cout << "Enter tag: ";
    	std::cin >> tag;
    
    	system(std::string("attrib " + tag).c_str());
    
    	return 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    Thanx swoopy it worked...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Any good windows system APIs?
    By taelmx in forum Windows Programming
    Replies: 2
    Last Post: 11-08-2006, 12:43 AM
  2. How to pass variable to Windows System?
    By jongmin in forum C++ Programming
    Replies: 2
    Last Post: 01-05-2004, 05:59 PM
  3. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. disabling system keys in a windows console
    By Shadow in forum Windows Programming
    Replies: 3
    Last Post: 06-23-2002, 07:06 PM