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++ system(variable); ??
Is there a way that I can pass a variable into the system() function?
I understand the syntax of the system command is: system(""); , but when I try to put a variable into the function, it gives me some really wierd and extensive error that I cannot remember off the top of my head.
Any help in this manner would be much appreciated ^_^
–Skunk
Okay, the variable I want to pass is in a struct. The variable is called "SendInfo.String", but when I try:
std::string myCmd = SendInfo.String;
system(myCmd.c_str());
I get:
Error : function call 'basic_string(apstring)' does not match
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &, unsigned int, unsigned int)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &, unsigned int, unsigned int, const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const char *, unsigned int, const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const char *, const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(unsigned int, char, const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(T1_0, T1_0, const std::allocator<char> &)'
'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string()'
MAIN.CPP line 294 std::string myCmd = SendInfo.String;
Do you think you understand this error? Can I not set myCmd = to SendInfo.String because it's a variable or something wierd like that?
#include "apstring.h" // Necessary for the string data type in my compiler (apstring)
#include <iomanip.h> // Necessary for formatting(setw, etc.)
#include <WinSIOUX.h> // Necessary for clearing the screen
struct NetSendType
{
char NetView;
apstring Method;
apstring String; // This is the only relevant variable in this case
};
NetSendType SendInfo; // Declares "SendInfo" as type "NetSendType"
#include <iostream>
#include <cstdlib>
#include "apstring.h"
struct NetSendType
{
char NetView;
apstring Method;
apstring String; // This is the only relevant variable in this case
};
int main()
{
NetSendType SendInfo;
apstring myCmd = SendInfo.String;
system(apstring.c_str());
return 0;
}