C ++: ¿La forma más fácil de acceder a la variable principal desde la función?

Actualmente estoy lidiando con una cadena inicializada en main () que por alguna razón se asusta (se convierte en una cadena de caracteres no) si trato de hacerlo global. Me pregunto si puedo hacer que una función declarada en el programa acceda a esta variable ... la función en sí misma solo se ejecutará en main o las funciones llamadas desde main, pero el compilador no ve el nombre de la variable hasta main () es alcanzado

Aquí hay una versión delgada del código relevante:

string getCommand(int input_pos,string inputstring)
{
int temp_paren=0;
int begin_pos = stdinstring.rfind("(",input_pos);
int len = 0;
while (temp_paren>0 && len < 10)
 {
 if (stdinstring.substr(begin_pos+len,1)=="(") {temp_paren++;}
 if (stdinstring.substr(begin_pos+len,1)==")") {temp_paren--;}
 len++;
 }
 return stdinstring.substr(begin_pos,len);
}

int main(void) {

string stdinstring = ""; 
}

He estado considerando declaraciones hacia adelante, pasando la variable a la función a mano cada vez que la uso, incluso haciendo una clase para mantener esa variable ... ¿Cuál sería la forma más sencilla de resolver este problema? Lo ideal sería tener tiempo suficiente para convertirlo en una variable global y averiguar dónde / por qué eso está yendo mal, pero solo necesito hacerlo. Gracias por cualquier y toda la ayuda

EDITA: Para cualquier persona interesada: Esto es lo que sucede si trato de hacer que la cadena sea global. Todos los caracteres se convierten en "" (no sé si eso es visible)

EDIT EDIT: Bien, aquí hay una versión más completa de mi código. Además, los símbolos que intenté pegar arriba eran cuadros con lo que parecía ser "0 0 0 1" (¿código de caracteres ASCII?)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<stdint.h>
//#include<regex>

#define PI M_PI
#define VERBOSE 1
using namespace std;

string stdinstring; 

template <class dataclass> 
struct linkm {
  dataclass value;
  linkm *next;
};

template <class dataclass> 
class linklist 
{
  public:
    linklist()
      {top = NULL;}
    ~linklist() 
      {}
    void push(dataclass num)
      {
      linkm<dataclass> *temp = new linkm<dataclass>;
      temp->value = num;
      temp->next = top;
      top = temp;
      } 
    dataclass pop()
      {
      if (top == NULL) 
        return 0;
      linkm<dataclass> * temp;
      temp = top;
      dataclass value;
      value = temp->value;
      top = temp->next;
      delete temp;
      return value;
      }
    bool isEmpty()
      {
      if (top == NULL) 
        return 1;
      return 0;
      }
  private:
    linkm<dataclass> *top; 
};

double evaluateExpression(string expression)
{
// sample expression : (* (/ a 1) (+ b 2))
     if (expression.substr(0,2)=="(+") {cout << "add found"<<endl;}
else if (expression.substr(0,2)=="(-") {cout << "sub found"<<endl;}
else if (expression.substr(0,2)=="(*") {cout << "mult found"<<endl;}
else if (expression.substr(0,2)=="(/") {cout << "div found"<<endl;}
else if (expression.substr(0,2)=="(sin") {cout << "sin found"<<endl;}
else if (expression.substr(0,2)=="(cos") {cout << "cos found"<<endl;}
else {cout << "Error: invalid operation";} // or is it just a number?
}

string getCommand(int input_pos,string inputstring)
{
int temp_paren=0;
int begin_pos = stdinstring.rfind("(",input_pos);
int len = 0;
while (temp_paren>0 && len < 10)
 {
 if (stdinstring.substr(begin_pos+len,1)=="(") {temp_paren++;}
 if (stdinstring.substr(begin_pos+len,1)==")") {temp_paren--;}
 len++;
 }
 return stdinstring.substr(begin_pos,len);
}

class symContainer
{
public:
string index[500];
float value[500];
int currindex;

symContainer () { currindex = 0 ; }

void add(string id,float invalue)
{
index[currindex] = id;
value[currindex] = invalue;
currindex++;
}

float get(string id)
{
int i=0;
while (i<currindex)
 {
 if(id==index[i]) {return value[i];}
 i++;
 }
 cout << "Invalid input - an unassigned symbol was requested:" << id << endl;
 exit(2);
}

};


struct transform { int type; double arguments[4]; } ;
struct point { double x; double y; } ;
struct drawing { linklist<point> points; linklist<transform> transforms; void applyTransforms(linklist<transform> * trsptr) {}  } ; 
struct group : public drawing { linklist<int> drawings; void transform(linklist<transform> * trsptr) {} } ;
struct symbol {string index; double value;};

char getNext() { //for the lookaround function. has hard-filters, like replacing newlines/tabs with spaces
char temp = getchar(); 
if (temp=='\n') {temp=' ';}
if (temp=='\t') {temp=' ';}
return temp;
}

int main(void) {

stdinstring="a";

char command[20], args[2048];
int commandindex=0;     //'i' for what command we're on
int stdinsize=2;
double argsArray[8];
bool filled=0;
int parenlevel = 0;
symContainer symbol;

//1 is the character that will be written at the end of each loop. 0 and 2 are 1 char ahead/behind, respectively
char c_lookaround[2]; 
c_lookaround[0]=NULL;
c_lookaround[1]=getNext();
c_lookaround[2]=getNext();

unsigned long i=0;

bool write=0;
while( c_lookaround[2] != EOF )
{ 
write=1;
// Lookaround logic goes here. (Clearing duplicate whitespaces, newlines, and the like)

while (                         c_lookaround[1]==' '  && c_lookaround[2]==' ' ) {c_lookaround[2]=getNext();}
while (c_lookaround[0]=='('  && c_lookaround[1]==' '                          ) {c_lookaround[1]=c_lookaround[2]; c_lookaround[2]=getNext();}
while (                         c_lookaround[1]==' '  && c_lookaround[2]==')' ) {c_lookaround[1]=c_lookaround[2]; c_lookaround[2]=getNext();}
while (c_lookaround[0]==NULL && c_lookaround[1]==' '                          ) {c_lookaround[1]=c_lookaround[2]; c_lookaround[2]=getNext();}
//while (c_lookaround[0]==')'  && c_lookaround[1]==' '  && c_lookaround[2]=='(' ) {c_lookaround[1]=c_lookaround[2]; c_lookaround[2]=getNext();}
//while (c_lookaround[0]==')'  && c_lookaround[1]==' '  && c_lookaround[2]=='\0' ) {cout<<"aa";c_lookaround[1]=c_lookaround[2]; c_lookaround[2]=getNext();}

if (c_lookaround[0]=='('  && c_lookaround[1]==':'  && c_lookaround[2]=='=') 
 {
    getCommand(i,stdinstring);
 }

//Determine current parentheses level
if (c_lookaround[1] == '(') { parenlevel++;}
if (parenlevel==0) {write=0;}
if (c_lookaround[1] == ')') { parenlevel--;}

//Write the character 
if (write) {stdinstring.push_back(c_lookaround[1]);}
cout << stdinstring<< endl;

//Advance the tape!
i++;
c_lookaround[0]=c_lookaround[1];
c_lookaround[1]=c_lookaround[2];
c_lookaround[2]=getNext();
}

stdinsize = i;

}

Respuestas a la pregunta(2)

Su respuesta a la pregunta