小编dea*_*mer的帖子

阵列差异之间的差异

我正在尝试将2D数组传递给函数.我尝试在互联网上提供不同的解决方案.

int arr[3][4];
fun (arr);



1) void fun(int *a[4]) {} -- result into a compilation error (cannot convert int (*)[4] to int **)

2) void fun(int(*a)[4]) {} -- works fine.
Run Code Online (Sandbox Code Playgroud)

我想知道上述两个声明之间有什么区别,以及1. case中有错误.

c

1
推荐指数
1
解决办法
132
查看次数

icu4c opentype harfbuzz之间的区别

这三个开源库非常常用于android.我只知道这些库用于处理字体.我在想这些图书馆之间的区别是什么?它们是否相互关联?或者他们可以互相替代.

opentype icu harfbuzz

1
推荐指数
1
解决办法
1031
查看次数

使用const_cast <>时出现意外输出

我写下面的代码我的机器(devcpp)和codepad.org但我的匹配工作正常,在codepad.org(http://codepad.org/XfW5a8en)输出是一个垃圾字符.

   #include <iostream>
    #include<cstring>
    using namespace std;
    int main () {
        char *str1 =const_cast<char*>(string("Hello ").c_str());
        char *str2 = const_cast<char*>(string("World!").c_str());
        char *ptr = str1;
        char *&rptr = str1;
        rptr = str2;
        std::cout << ptr << str1 << std::endl;
    }
Run Code Online (Sandbox Code Playgroud)

我期待输出为Hello World!

c++ const-cast

1
推荐指数
1
解决办法
85
查看次数

天花板,地板将如何在TreeSet of String上运行

我正在阅读TreeSet并发现它很有趣.我有一个问题让我们有一个TreeSetString.在这种情况下,这个Ceilingfloor函数将如何表现.

    NavigableSet<String> ns= new TreeSet<String>();
    ns.add("Yogi");
    ns.add("Yogendra");
    ns.add("Yogesh");
    ns.add("hello");
    String ns1= ns.ceiling("Yog");
    System.out.println(ns1);

Output==> Yogendra
Run Code Online (Sandbox Code Playgroud)

java treeset

1
推荐指数
1
解决办法
3674
查看次数

关于const_cast <>的行为

我写了一个小问题来检查const数据成员上const_cast的行为.

using namespace std;


     class myString{
         public:
                 myString(char * str)
                 {
                         p=str;
                 }
                 const char * getString(){
                         return p;
                 }
         private:
                 const char *p;
 } ;


int main()
{
        char *p=(char*)malloc(8);
        cin>>p;
        myString *m= new myString(p);
        char *s =const_cast<char*>(m->getString());
        s[6]='y';
        cout<<s<<endl;
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

运行此程序后,我将其作为"yogendra"(8个字母的字符串).我把输出称为"yogendya"现在我怀疑了.通过const_cast <>我们可以覆盖数据成员本身的行为,因为这里的字符串是const char*仍然在转换后我可以修改它.

c++ const-cast

0
推荐指数
1
解决办法
191
查看次数

反转字符串的递归方法

我正在尝试编写一个反转字符串的递归方法,如下所示.

void reverse(string s,int i,int l)
{
    static int j;
    while(i<l)
    {
        char ch=s[i];
        cout<<ch<<endl;
        reverse(s,i+1,l);
        cout<<"after="<<ch<<endl;
        s[j]=ch;
        j++;
    }
    cout<<s<<endl;
    s[j]=0;
}
Run Code Online (Sandbox Code Playgroud)

但我的输出不正确."after="<<ch始终打印字符串的最后一个字符.函数的参数是s是std :: string,i是从0开始的索引,l是字符串的长度.任何人都可以指出我做错事的地方.

c++ string

0
推荐指数
1
解决办法
874
查看次数

计算开口支架的最大深度

有如下四种形状的括号.

类型1:'('或')'

类型2:'{'或'}'

类型3:'['或']'

类型4:'<'或'>'

如果只有如上所示的由四个形状的括号组成的字符串,请编写一个函数以返回最内部括号的深度.深度由重叠程度定义.最外侧托架的深度为1,最外侧托架内侧的托架深度为2,托架内侧的深度为3.

示例: - "{([])[()(<>)]}"此处最大深度为4.让字符串包含有效括号.

algorithm

0
推荐指数
1
解决办法
1039
查看次数

在c ++中链接"C"样式代码

我试图在C++中运行C样式代码,我的编译器给出以下错误:

第5行:错误:字符串常量之前的预期unqualified-id

第二:我的目标是理解"第d行"的错误.

using namespace std;
typedef int (*pfun)(int);        // line a
int main()
{
    extern "C" void foo(pfun);   // line b
    extern "C" int g(int);       // line c 
    foo( g );                    // line d, Error

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ extern

-1
推荐指数
1
解决办法
154
查看次数

标签 统计

c++ ×4

const-cast ×2

algorithm ×1

c ×1

extern ×1

harfbuzz ×1

icu ×1

java ×1

opentype ×1

string ×1

treeset ×1