I want to print the value of my macros through a string Given Code
#include<iostream>
#define abc 7
using namespace std;
int main()
{
string str = "abc";
cout<<str<<endl;
}
Output should be 7 if i do cout str
I want to print the value of my macros through a string Given Code
#include<iostream>
#define abc 7
using namespace std;
int main()
{
string str = "abc";
cout<<str<<endl;
}
Output should be 7 if i do cout str
You cannot. Macro expansion occurs in early translation phases before actual compilation. That means that your requirement cannot be achieved in C++. But std::map
(or std::unordered_map
) is a associative container implementation that can be used to convert strings at run-time