English 中文(简体)
汇编 c级代码
原标题:compile c++ code in c mode
  • 时间:2011-11-23 08:49:03
  •  标签:
  • c++
  • c
  • c-mode

下面是我的法典,作为文件存档和存档。

in .c it compiled fine, but threw the following error in .cpp

test.cpp:6: error: initializer-string for array of chars is too long
test.cpp:6: error: initializer-string for array of chars is too long

 

#include< stdio.h>

int main()
{

char str[2][2]= { "12", "12"};
int i;

for(i=0; i<2; i++)
printf("%d %s
", i, str[i]);

return 0;
}

是否有任何汇编者指令或任何指示,以便编造者将这一指示作为C代码。

我曾尝试过“C”号,但却没有帮助。

最佳回答

虽然这无助于你的问题,但你可以选择语言汇编。 悬挂该国旗后,需要使用文字。 和gcc一样,x c. c.cpp.将使用汇编器汇编。

问题回答

“12”的特性在C++中占有3个位置(在C.,BTW)。 您在终止<条码>时需要另外一份文件。

char str[2][3]= { "12", "12"};

这样做是适当的。

char str[2][2] = {
  {  1 ,  2  },
  {  1 ,  2  }
};

但希望:https://ideone.com/wZB8F

char str[2][3]= { "12", "12"};

Otherwise, there is no room for the terminating null character

等值:

char str[2][3]= { {  1 ,  2 ,    },
                  {  1 ,  2 ,    } };

C++是一种比C更严格的语言。 问题在于,你创建一系列包含两种特性的阵列,然后指定每个分属三个特性(序列 1 , 2 和string terminator )。

应宣布这种阵列:

char str[2][3]= { "12", "12"};

汇编者为这一目的贴上了旗帜,并绕过了扼杀装置,因此,您的<代码>f声明很有可能在扼杀后打印垃圾。

#include< stdio.h>

int main() 
{
    char str[][3]= { "12","12"}; 
    int i;

    for(i=0; i<2; i++) 
    {
        printf("%d %s
", i, str[i]);
    }

    return 0; 
}

该版本将在C++......使用。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签