English 中文(简体)
强化的多面理论
原标题:Complicated multi-argument #define macro for strings

我致力于一个项目,我相信这个问题可以宏观解决,但鉴于问题的性质,我没有亲身思考的经验。

这里,我期望作为“目标宏观”的投入和产出:

投 票

printf(foobar(Hello World.));

1. 如果形成加工前生产法,其内容如下:

printf((char *)(std::string("")+ H + e + l + l + o +   + W + o + r + l + d + . ).c_str());

我假定这种复杂情况是可能的,我希望你们中的一位能够帮助我。

I NEED IT to BE A MACRO, I DO NOT想要在任何地方保持固定不变。

最佳回答

我认为,唯一的解决办法是通过适当的文字来操作你的代码(或许只是一些灯光awk),而代号在您的法典达到事先汇编之前就是这样做的。

根据你们的环境,你可以在视力演播室中作为“前活动”来做,或只是把一个步骤直接添加到你的档案中。

问题回答

Uh, I fear it is impossible (unless I don t know something). I believe there is no macro to split a given input token (e.g. Hello) into characters building it (H e l l o)

There were some attempts to do such thing, but I fear it is not exactly what you need:

C++: 宏观将“abc”扩大为“、b、c、


"More powerful precompiler" ?

专题:Replacements for the C preprocessor

Macros are basically substitution or addition of strings. You could do this with a pre-processor of your own, but the standard pre-processor won t split strings into component parts.

How about this: Put all these (assuming there is more than one) macros in a separate file. Write a program that translates them into the expansion you require and then include THAT file in your c program? You could then make the expansion program part of your make file so it s always up to date. Using a separate file makes the expansion program much easier than parsing a c/c++ file.

既然你重新寻找对你的问题的狭隘、直接的回答,而没有提出建议,那么:

这是不可能的。 你们必须找到另一种解决办法,解决你们重新努力实现的目标。

您:

#define toString(x) #x

你们可以这样做:

printf("%s", toString(hello world));

Don t试图直接使用插图,因为你在插图中可以有格式的光谱。

printf(toString(hello world)); //wrong, you can have for example %d in the string




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签