标签: declaration

文档中的 dom4j XML 声明

我需要从 dom4j 文档类型中删除 XML 声明

我正在创建文档

doc = (Document) DocumentHelper.parseText(someXMLstringWithoutXMLDeclaration);
Run Code Online (Sandbox Code Playgroud)

由 DocumenHelper 解析为 Document doc 的字符串不包含 XML 声明(它来自 XML => XSL => XML 转换)我认为 DocumentHelper 正在向文档正文添加声明?

有没有办法从正文中删除 XML 声明

doc
Run Code Online (Sandbox Code Playgroud)

java xml declaration dom4j

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

在for循环中声明变量

我正在尝试以下C代码:

void main()
{
   int i;
   for(i = 0; i< 10; i++)
   { 
      int num;
      printf("\nthe variable address is: %p", &num);

   }
   getch();
}
Run Code Online (Sandbox Code Playgroud)

我原以为它要么抛出错误要么num多次声明,而是&num对于for循环的所有迭代,输出显示相同的值.这种行为背后的原因是什么?似乎无论在for循环中都有声明,实际的声明/定义只发生一次.

有人能帮我理解这种行为吗?

c loops for-loop declaration

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

为什么需要定义一些参数,而其他参数不需要?(以艰难的方式学习Python,例如25)

通过学习Python艰难的方式ex.25工作,我只是无法绕过一些东西.这是脚本:

def break_words(stuff):
    """this function will break waords up for us."""
    words = stuff.split(' ')
    return words

def sort_words(words):
    """Sorts the words."""
    return sorted(words)

def print_first_word(words):
    """Prints the first word after popping it off."""
    word = words.pop(0)
    print word

def print_last_word(words):
    """Prints the last word after popping it off."""
    word = words.pop(-1)
    print word

def sort_sentence(sentence):
    """Takes in a full sentence and returns the sorted words."""
    words = break_words(sentence)
    return sort_words(words)

def print_first_and_last(sentence):
    """Prints the first and last words of …
Run Code Online (Sandbox Code Playgroud)

python arguments declaration

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

怀疑'for'语句是如何工作的

有一些我对for语句没有理解的东西,在下面的代码中请集中注意力??? 评论:

void user_interface::execute_a_command( const string& cmd, command cmd_table[] )
{
    LOG("user_interface::execute_a_command(): Executing \"",cmd,"\"");
    bool command_executed = false;
    //Exist any operation for this command?
    command* elem = &cmd_table[ 0 ]; //???
    for( int i = 0 ; cmd_table[ i ].function != nullptr ; i++, elem = &cmd_table[ i ] )
    {
        if( cmd == elem->name )
        {
            //Call the function
            (this->*(elem->function))();
            command_executed = true;
            break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

好吧,这段代码编译得很好,没有特别的警告.但是,如果我将'elem'的声明和初始化放在'for'语句中,如下所示:

for( int i = 0 , command* elem = &cmd_table[ 0 ] …
Run Code Online (Sandbox Code Playgroud)

c++ for-loop declaration

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

2
推荐指数
2
解决办法
316
查看次数

为什么这个Perl变量保持其值

以下两个Perl变量声明之间有什么区别?

my $foo = 'bar' if 0;

my $baz;
$baz = 'qux' if 0;
Run Code Online (Sandbox Code Playgroud)

当它们出现在循环的顶部时,差异很大.例如:

use warnings;
use strict;

foreach my $n (0,1){
    my $foo = 'bar' if 0;
    print defined $foo ? "defined\n" : "undefined\n";
    $foo = 'bar';
    print defined $foo ? "defined\n" : "undefined\n";
}

print "==\n";

foreach my $m (0,1){
    my $baz;
    $baz = 'qux' if 0;
    print defined $baz ? "defined\n" : "undefined\n";
    $baz = 'qux';
    print defined $baz ? "defined\n" : "undefined\n";
}
Run Code Online (Sandbox Code Playgroud)

结果是

undefined …
Run Code Online (Sandbox Code Playgroud)

variables perl initialization declaration

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

奇怪的C++指针声明

我正在编写一个关于深度优先搜索算法的小程序.在程序结束时,需要删除内存.

for(int i = 0; i < V; i++) {
    Vertex* temp1, *temp2 = graph->adjacentList[i];
    while(temp1 != NULL) {
        temp2 = temp1->next;
        delete temp1;
        temp1 = temp2;
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码删除图表的相邻列表.代码可以编译并运行但运行时错误.错误消息是

变量'temp1'正在使用而未初始化.

请看另一段代码:

for(int i = 0; i < V; i++) {
    Vertex* temp1 = graph->adjacentList[i];
    Vertex* temp2 = graph->adjacentList[i];
    while(temp1 != NULL) {
        temp2 = temp1->next;
        delete temp1;
        temp1 = temp2;
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码可以编译和运行,没有任何错误消息!唯一的区别是声明.这很奇怪,至少对我而言.

任何人都可以想出一个主意吗?

c++ pointers declaration

2
推荐指数
2
解决办法
102
查看次数

"int*(&arry)[10] = ptrs;"是什么意思?你怎么看这样的?

我是C++的新手,正在尝试学习数组的概念.我知道

int *ptrs[10]; 
Run Code Online (Sandbox Code Playgroud)

有ptrs的含义是一个十点指向int的数组.那怎么样

int *(&arry)[10] = ptrs;
Run Code Online (Sandbox Code Playgroud)

我对它的语法很困惑,所以有人可以向我解释它的含义是什么以及如何阅读它?如果有人可以将其分解并以较小的部分进行解释,那将是很棒的.

c++ arrays pointers reference declaration

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

C中的函数定义,函数调用和声明语句是?

当我们讨论C语句时,我们通常会想到表达式语句,循环语句,条件分支语句和无条件跳转语句.

以下是C编程语言中的语句:

  • 函数定义(包括main函数的定义,因程序而异.在Bash中,函数定义是一个命令,我认为它是语句的同义词.),
  • 函数调用,(我猜可以是表达式语句,但我不确定调用返回的函数void)
  • 声明(例如对象,函数,类型声明)?

如果其中一些不是陈述,它们分别是什么?

谢谢.

c declaration function definition

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

Java中简单String对象的错误

我正在尝试编译以下代码:

public class Test {

    public static void main(String[] args) {
        String final = new String("");
        final = "sample";
        System.out.println(final);
    }
}
Run Code Online (Sandbox Code Playgroud)

显然,编译器向我显示以下错误:

Test.java:5: error: not a statement
    String final = new String("");
    ^
Test.java:5: error: ';' expected
    String final = new String("");
          ^
Test.java:5: error: illegal start of type
    String final = new String("");
                 ^
Test.java:6: error: illegal start of type
    final = "sample";
          ^
Test.java:7: error: illegal start of expression
    System.out.println(final);
                       ^
Test.java:7: error: illegal start of type …
Run Code Online (Sandbox Code Playgroud)

java string declaration declare

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