小编Fre*_*son的帖子

如何隐藏Django表单中的主键字段

我更喜欢我的主键字段在我的编辑页面中不可见.如果我将其设置为AutoField,则不会在HTML表单中呈现它.但是主键值也不在我的POST数据中.有没有一种简单的方法将AutoField渲染为隐藏字段?

django django-forms

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

如何使用python获取xml文件中的特定节点

我正在寻找一种获取特定标签的方法..来自一个非常大的xml文档,
例如内置模块中的python dom :

<AssetType longname="characters" shortname="chr" shortnames="chrs">
  <type>
    pub
  </type>
  <type>
    geo
  </type>
  <type>
    rig
  </type>
</AssetType>

<AssetType longname="camera" shortname="cam" shortnames="cams">
  <type>
    cam1
  </type>
  <type>
    cam2
  </type>
  <type>
    cam4
  </type>
</AssetType>
Run Code Online (Sandbox Code Playgroud)

我想检索具有属性(longname ="characters")的AssetType节点的子节点的值,以便得到结果'pub','geo','rig'
请记住我
提前有超过1000个<AssetType>节点而不是x

python xml

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

如何向 C++ 控制台应用程序添加图标?

我正在尝试向我的 C++ 控制台应用程序添加一个图标,但是当我尝试编译以下代码时,出现了这些错误。第一个文件是我的 resources.rc,第二个文件是我的 main.cpp。

资源脚本:
#ifndef RESOURCE_RC_INCLUDED
#define RESOURCE_RC_INCLUDED

MAINICON  ICON  "icon.ico"

#endif // RESOURCE_RC_INCLUDED`
Run Code Online (Sandbox Code Playgroud) C++ 源代码:
#ifndef RESOURCE_RC_INCLUDED
#define RESOURCE_RC_INCLUDED

MAINICON  ICON  "icon.ico"

#endif // RESOURCE_RC_INCLUDED`
Run Code Online (Sandbox Code Playgroud)

这些是我得到的错误。

||=== Build: Debug in Shima (compiler: GNU GCC Compiler) ===|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\resources.rc|4|错误:'MAINICON' 没有命名类型|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp||在函数'int main()'中:|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|错误:'string' 未在此范围内声明|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|注:建议替代:|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stringfwd.h|65|注意:'std::string'|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|错误:应为';' 在'名字'之前|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|36|error: expected ';' 在'cmds'之前|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|37|错误:应为';' 在'笑话'之前|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|38|错误:预期的';' 在'prg'之前|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|错误:'cout' 未在此范围内声明|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|注:建议替代:|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\iostream|62|注意:'std::cout'|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|错误:'endl' 未在此范围内声明|
C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|注:建议替代:| …

c++ console-application ico

5
推荐指数
0
解决办法
7665
查看次数

重复的班级限定词被接受。为什么?

一位同事给我发送了类似于以下代码:

#include <iostream>

class Weird
{
public:
    Weird();
};

Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird::Weird()
{
    std::cout << "Ok, this is weird.\n";
}

int main()
{
    Weird a;
}
Run Code Online (Sandbox Code Playgroud)

它编译运行并产生“好吧,这很奇怪”。我在在线编译器中使用g ++,clang和msvc进行了尝试,并且可以在所有这些程序上使用。

为什么要接受重复的类名限定符?这是标准要求的吗?

c++

5
推荐指数
0
解决办法
59
查看次数

在iPhone上运行C++的限制是什么?

我很喜欢C++,说实话,C的Objective-C"超级集"更像是"超级失败".iPhone应用程序可以用纯C++编写吗?是否有部分API不可用于C++?

c++ iphone objective-c

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

c ++中的指针列表

我想做的是

for (list<cPacket *>::iterator i = cache.begin(); i != cache.end(); i++){
        if( strcmp(i->getName(),id) == 0 ){
            return true;
        }
}
Run Code Online (Sandbox Code Playgroud)

哪个getName是类cPacket的功能,但是它不起作用,我也尝试了 i.operator->()->getName(),而且一无所获.

有谁能够帮我?

c++ pointers list

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

C++如果编译器隐式创建它们,那么析构函数的目的是什么?

我读到的每个地方,如果没有定义析构函数,编译器无论如何都会创建一个析构函数.那么明确定义一个是什么意义呢?

谢谢

c++

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

从函数返回值存储char*

我正在尝试实现一个从串行端口(Linux)读取并返回char*的函数.该函数工作正常,但我如何存储函数的返回值.功能的例子是

char  *ReadToSerialPort()
{
 char *bufptr;
 char buffer[256];  // Input buffer/ /
 //char *bufptr;      // Current char in buffer //
 int  nbytes;       // Number of bytes read //

 bufptr = buffer;

 while ((nbytes = read(fd, bufptr, buffer+sizeof(buffer)-bufptr -1 )) > 0)
 {
  bufptr += nbytes;
  //  if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
  /*if ( bufptr[sizeof(buffer) -1] == '*' && bufptr[0] == '$' )
  {
   break;
  }*/

 } // while ends


 if ( nbytes ) return bufptr;
 else return …
Run Code Online (Sandbox Code Playgroud)

c linux

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

将文本框字符串转换为浮点数?

我基本上试图在visual studio 2008中编写一个基本的转换器,我有两个文本框,一个用户输入,另一个用输出结果.当我按下按钮时,我希望第一个文本框中的输入乘以4.35然后显示在第二个文本框中.到目前为止,这是我在按钮代码中的代码:

             String^ i1 = textBox1->Text;
             float rez = (i1*4.35)ToString;
             textBox2->Text = rez;
Run Code Online (Sandbox Code Playgroud)

但是我收到这些错误:

f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2676: binary '*' : 'System::String ^' does not define this operator or a conversion to a type acceptable to the predefined operator
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2227: left of '->ToString' must point to class/struct/union/generic type
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(149) : error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'float' to 'System::String ^'
Run Code Online (Sandbox Code Playgroud)

请帮助我疯狂地从C++中的文本框中获取一些输入是多么的荒谬.我用谷歌搜索了我的每一个错误,没有任何有用的信息,我已经找了一个小时的答案,请帮忙.

c++ textbox c++-cli

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

对异常处理的C++编程实践的困惑

我有一个下面提到的C++代码:

#include<iostream>
#include<stdexcept>

const long MAX = 10240000;

class Widget{
      public:
             Widget(){
                      ok = new int [1024];
                      prob = new int [100*MAX];
             }
             ~Widget(){
                       std::cout<<"\nDtoR of Widget is called\n";
                       delete ok; ok = NULL;
                       delete prob; prob = NULL;
             }
             //keeping below public: Intentionally
              int* ok;
              int* prob;
};


void func(){
    Widget* pw = NULL;  // <<<<--------------- Issue in Here
    try{
        pw = new Widget;
    }
    catch(...){
               delete pw;
               std::cout<<"\nIn catch BLOCK\n";
               if(pw->ok == NULL){
                      std::cout<<"\n OK is NULL\n";
               } …
Run Code Online (Sandbox Code Playgroud)

c++ exception-handling

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