Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7188265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:02:19+00:00 2026-05-28T19:02:19+00:00

The preprocessor can be used to replace certain keywords with other words using #define

  • 0

The preprocessor can be used to replace certain keywords with other words using #define. For example I could do #define name "George" and every time the preprocessor finds ‘name’ in the program it will replace it with “George”.

However, this only seems to work with code. How could I do this with strings and text? For example if I print “Hello I am name” to the screen, I want ‘name’ to be replaced with “George” even though it is in a string and not code.

I do not want to manually search the string for keywords and then replace them, but instead want to use the preprocessor to just switch the words.

Is this possible? If so how?

I am using C++ but C solutions are also acceptable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:02:21+00:00Added an answer on May 28, 2026 at 7:02 pm
    #define name "George"
    
    printf("Hello I am " name "\n");
    

    Adjacent string literals are concatenated in C and C++.

    Quotes from C and C++ Standard:

    For C (quoting C99, but C11 has something similar in 6.4.5p5):

    (C99, 6.4.5p5) “In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed string literal tokens are concatenated into a single multibyte character sequence.”

    For C++:

    (C++11, 2.14.5p13) “In translation phase 6 (2.2), adjacent string literals are concatenated.”

    EDIT: as requested, add quotes from C and C++ Standard. Thanks to @MatteoItalia for the C++11 quote.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using C preprocessor one can stringify macro argument like this: #define TO_STRING(x) a
Is there a single preprocessor token that can be used to detect any iPhone
Can you write preprocessor directives to return you a std::string or char*? For example:
I am using some preprocessor commands in my project so that I can specify
Preprocessor directive lines like #define #include #ifdef and #endif #if and #elif can be
How can I check the size of an unsigned in the preprocessor under g++?
C++ preprocessor #define is totally different. Is the PHP define() any different than just
I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...)
We have a set of C macros, here, for using the preprocessor to do
What are the best practices for using autoconf in conjunction with shared_ptr and other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.