-1

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

glennsl
  • 28,186
  • 12
  • 57
  • 75

1 Answers1

3

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

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252