I'm starting to write more intricate code that does some dynamic compilation through Lua and OpenGL. However, my code is starting to get kinda messy because I have many const char* strings and strings in sections of my code so they can be parsed together properly depending on specific conditions. The only method I know for structuring strings across multiple lines is:

const char* foo = "1\n\
2\n\
3";

prints --
1
2
3

Is there a better way as this looks messy? Maybe some method of using \b*number.

Visual Studio automatically does this but unfortunately it puts all the spaces on the line leading too it.

const char* foo = "1\n\
                   2\n\
                   3";
prints --
1
                   2
                   3

I don't really want to do \b\b\b\b\b\b\b\b\b\b\b\b\b\b or something silly or even count the backspaces unless I have to. Any ideas?

Recommended Answers

All 2 Replies

one way is:

const char* foo = "\n1\n2\n3\n4"

another is

char* foo[] = {"1", "2", "3"}
int count = 3;
for(i=0;i<3;i++)
  printf("\n%s", foo[i]);

Guess nothing as convenient as lua's --[[ --]] operators. Never really had a need for such long strings so never really looked into it.

commented: What's the purpose of this post? -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.