Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ variables && system()


Zeke tAh FreKe's Avatar
The Merchant
0 0

I'm trying to make a project where I can pass variables through the system() function.

EX:


cin << message;

system("msg * 'your message is: ' << message");

Thats not the exact code I'm using but its the gist.

Any suggestions ?


Zeke tAh FreKe's Avatar
The Merchant
0 0

That was merely a brief explanation of how system() works.

I'm looking for a way to include variables in the function.

§orta like Cout.

cout << " text " << var << " more text " ;


ghost's Avatar
0 0

Zeke, that's now how it works.

use "cout" if you simply wanted to manipulate how your strings are getting displayed in your program. If you wanted to interact with the OS, then use the system() function. Look at this example and get an idea of how it works:

directory=system ("dir");

You can also use:

system("pause");

It's the equivalent of the:

getchar();

Simply pauses the system and wait for the user to press [ANY] key.

cin &lt;&lt; message;
system(&quot;msg * &#39;your message is: &#39; &lt;&lt; message&quot;);```

That won&#39;t work. You&#39;re trying to use System, like &quot;cout&quot;. Do:

> 
String message;
cin &gt;&gt; message;
cout &lt;&lt; &quot;Your Message is&quot; &lt;&lt; message;

+ You only use single quotes for single character. And double quotes for strings. Hope you get the idea.

+ Also, your &quot;cin&quot; and &quot;cout&quot; operators are reversed. For &quot;cin&quot; it&#39;s &gt;&gt;, and for &quot;cout&quot; it&#39;s &lt;&lt;. Practice will make you remember.