小编Rob*_*obᵩ的帖子

不完整的类型

我为'next'和'previous'变量得到了一个不完整的类型错误.我不确定我做错了什么,因为我在用C++编写类时非常生疏.任何帮助,将不胜感激!谢谢.

#include<iostream>

using namespace std;

class LinearNode
{
    public:
        //Constructor for the LinearNode class that takes no arguments 
        LinearNode();
        //Constructor for the LinearNode class that takes the element as an argument
        LinearNode(int el);
        //returns the next node in the set.
        LinearNode getNext();
        //returns the previous node in the set
        LinearNode getPrevious();
        //sets the next element in the set
        void setNext(LinearNode node);
        //sets the previous element in the set
        void setPrevious(LinearNode node);
        //sets the element of the node
        void setElement(int el); …
Run Code Online (Sandbox Code Playgroud)

c++ incomplete-type

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

不同语言中相同算法的不同输出

Java源代码:

package n1_problem;

/**
 *
 * @author nAwS
 */
public class loop {

    int loop(long i)
    {
        long n=i;
        int count=1;
        while(n>1){
            if(n%2==0){
                n=n/2;
            }
            else{
                n=3*n+1;
            }
            count++;
        }
       return count; 
    }

    int max_cycle(long j,long k){

        int max=-1;
        for(long i=j;i<=k;i++){
            int count=loop(i);
            if(count>max){
                max=count;
            }
        }
        return max;
    }


}


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        loop lp=new loop();
        System.out.println("Max Cycle:"+lp.max_cycle(1,1000000));
    }

}
Run Code Online (Sandbox Code Playgroud)

C源代码:

int main() …
Run Code Online (Sandbox Code Playgroud)

c java algorithm

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

模板运动问题

我正在尝试使用Thinking in C++ Vol 2进行以下练习,女巫说:

在以下代码中,类NonComparable没有operator =().为什么HardLogic类的存在会导致编译错误,但SoftLogic不会?

#include <iostream>
using namespace std;

class NonComparable {};

struct HardLogic {
    NonComparable nc1, nc2;
    void compare()
    {
        return nc1 == nc2;
    }
};

template<class T>
struct SoftLogic {
    NonComparable nc1, nc2;
    void noOp() {}
    void compare()
    {
        nc1 == nc2;
    }
};

int main()
{
    SoftLogic<NonComparable> l;
    l.noOp();

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

1)HardLogic :: compare返回void但函数尝试返回int/bool.
2)SoftLogic也有一些奇怪的东西(对我来说):nc1 == nc2.
3)练习说的是operator =(),但在代码中它使用的是operator ==().

是错误吗?我发现在这样一本书的代码中出现如此多的错误很奇怪,所以我错过了一些东西吗?以前有没有人遇到这个练习?

c++

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

使用strcpy从'char'无效转换为'char*'

好的,我的代码部分是我遇到的问题:

char * historyArray;
historyArray = new char [20];

//get input
cin.getline(readBuffer, 512);       
cout << readBuffer <<endl;

//save to history
for(int i = 20; i > 0; i--){
    strcpy(historyArray[i], historyArray[i-1]); //ERROR HERE//  
}

strcpy(historyArray[0], readBuffer); //and here but it's the same error//
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

"invalid conversion from 'char' to 'char*' 
           initializing argument 1 of 'char* strcpy(char*, const char*)'
Run Code Online (Sandbox Code Playgroud)

该项目是创建一个psudo OS Shell,它将捕获和处理中断以及运行基本的unix命令.我遇到的问题是我必须将过去的20个命令存储到在堆栈上动态分配的字符数组中.(还要取消分配)

当我只使用2d字符数组时,上面的代码工作正常:

char historyArray[20][];
Run Code Online (Sandbox Code Playgroud)

但问题是它不是动态的......

是的,我知道strcpy应该用于复制字符串.

任何帮助将不胜感激!

c++ char strcpy

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

为什么svn commit会更改时间戳?

我正在SVN版本控制下的C++项目.这是我典型的工作流程:

  • 在工作副本中做一些更改
  • 构建和测试项目
  • 承诺

在最后一步之后,提交文件的所有时间戳都将更改为当前时间.这很不方便,因为依赖于这些文件的项目的所有部分将再次重建,尽管它们的内容在提交后没有改变(仅时间戳).

  • 为什么这种行为有用?
  • 我可以配置svn来禁用它吗?

svn timestamp

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

c ++异常处理按引用传递:抛出的地址与捕获的地址不同?

#include <iostream>
#include <exception>
using namespace std;


class myexception: public exception
{
  virtual const char* what() const throw()
  {
    return "My exception happened";
  }
};

int main ()
{
  try
  {
    myexception myex;
    printf("addr1:%x\n",&myex);
    throw myex;
  }
  catch (exception& e)
  {
    printf("addr2:%x\n",&e);
    cout << e.what() << endl;
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

该程序的输出:

addr1:6d78c020
addr2:20a1080
My exception happened
Run Code Online (Sandbox Code Playgroud)

问题:你看到addr1和addr2是不同的,任何想法为什么?

c++

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

是或否输出Python

Join = input('Would you like to join me?')
if Join == 'yes' or 'Yes':
  print("Great," + myName + '!')
else:
  print ("Sorry for asking...")
Run Code Online (Sandbox Code Playgroud)

所以这是我的代码.它更长; 只是包括问题.我问一个是或否的问题,在控制台中它运行顺利直到你到达它.无论你输入什么,你都会得到'是'的输出.有人可以帮忙吗?我也使用过elif语句,但没有运气.

python variables

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

Python没有打印所有的sys.argv

我从sys.argv [1]得到一个超出范围错误的列表,我尝试用这段代码制作一个简单的脚本.

import sys
print sys.argv
Run Code Online (Sandbox Code Playgroud)

我在cmd上得到这个:

C:\...\...\...\py>back.py exampleargv
['C:\\...\\...\\...\\py\\back.py']
Run Code Online (Sandbox Code Playgroud)

我不知道为什么我没有得到下一个arg.

python windows sys command-line-arguments python-2.7

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

对等待100的JIRA REST API的Pycurl PUT请求继续

我正在尝试使用pycurl更改JIRA中的受让人.我的代码正在等待****HTTP/1.1 100继续****.我究竟做错了什么?谢谢你的帮助.我在下面附上了我的代码片段.另外,我不想使用JIRA Python库.

def assign(self, key, name):

    data = json.dumps({"fields":{"assignee":{"name":name}}}) 
    c= pycurl.Curl()
    c.setopt(pycurl.VERBOSE, 1)
    c.setopt(pycurl.URL, "http://xxx/rest/api/2/issue/"+ key )
    c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json'])
    c.setopt(pycurl.USERPWD, "****") 
    c.setopt(pycurl.PUT, 1) 
    c.setopt(pycurl.POSTFIELDS,data)
    c.perform()
Run Code Online (Sandbox Code Playgroud)

python put pycurl

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

使用 Python Flask 将 html 转换为 pdf

这是我在 myclass.py 中的代码

class Pdf():

    def render_pdf(self,name,html):


        from xhtml2pdf import pisa
        from StringIO import StringIO

        pdf = StringIO()

        pisa.CreatePDF(StringIO(html), pdf)

        return pdf
Run Code Online (Sandbox Code Playgroud)

我像这样在 api.py 中调用它

@app.route('/invoice/<business_name>/<tin>', methods=['GET'])
def view_invoice(business_name,tin):

   #pdf = StringIO()
  html = render_template('certificate.html', business_name=business_name,tin=tin)
file_class = Pdf()
pdf = file_class.render_pdf(business_name,html)
return pdf
Run Code Online (Sandbox Code Playgroud)

但它抛出这个错误

AttributeError: StringIO instance has no __call__ method
Run Code Online (Sandbox Code Playgroud)

python flask

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