Strange character in place of the directory

1

When I run this code in the place where it was to appear the directory appears Ó²o \ formula.exe , could someone help me solve?

#include <iostream>
#include <Windows.h>
#include <lmcons.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string>

using namespace std;

string teste() {
    char buffer[MAX_PATH];
    GetModuleFileName( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\/" );
    return string( buffer ).substr( 0, pos);
}


int main(){
        TCHAR teste[MAX_PATH];
        cout << teste << endl;


        string cmd = "reg add HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run /t REG_SZ /v formula /d ";
        cmd += teste;
        cmd += "\formula.exe";


       cout << cmd.c_str() << endl;

        system(cmd.c_str());



}
    
asked by anonymous 23.05.2018 / 06:10

1 answer

0
#include <iostream>
#include <Windows.h>
#include <lmcons.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string>

using namespace std;

string dir() {
    char buffer[MAX_PATH];
    GetModuleFileName( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\/" );
    return string( buffer ).substr( 0, pos);
}



int main(){


cout << dir() << endl;
        string cmd = "reg add HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run /t REG_SZ /v formula /d ";
        cmd += dir();
        cmd += "\formula.exe";

        cout << cmd.c_str() << endl;

        system(cmd.c_str());

    return 0;
    
23.05.2018 / 07:04