Search code examples
c++convertersc++buildershellexecuteborland-c++

AnsiString does not work (AnsiString identifier is not defined)


Here's the code:

AnsiString path = "BrowserBot.exe";
ShellExecute(0, TEXT("open"), path.c_str(), TEXT("-parametr"), 0, SW_SHOW);

Writes an error that the AnsiString identifier is not defined. I don't know what the problem is.

All connected libraries:

#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <fstream>
#include <sstream>

Solution

  • AnsiString is a string class that is specific to the C++Builder compiler. If you are using that compiler, make sure you are compiling your project with C++Builder's VCL (Visual Component Library) or FMX (FireMonkey) framework enabled, and that you have a corresponding #include <vcl.h> or #include <fmx.h> statement in your C++ code.

    Otherwise, if you are using any other compiler, you should use the standard C++ std::string class instead (which can also be used in C++Builder), eg:

    #include <string>
    
    std::string path = "BrowserBot.exe";
    ShellExecuteA(0, "open", path.c_str(), "-parametr", 0, SW_SHOW);