-
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?
-
You need to build the string to pass to system, using sprintf or stringstreams or something similar.
-
>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;
}
-
Thanx swoopy it worked...