Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mingwCC编译错误(EclipseJuno) < >好的,所以我现在正在尝试编译一些东西,我对C++是新的,所以代码本身可能会导致错误,但是Eclipse正在显示的代码本身中没有红色标记出现。_C++_Compiler Errors_Mingw_Eclipse Juno - Fatal编程技术网

mingwCC编译错误(EclipseJuno) < >好的,所以我现在正在尝试编译一些东西,我对C++是新的,所以代码本身可能会导致错误,但是Eclipse正在显示的代码本身中没有红色标记出现。

mingwCC编译错误(EclipseJuno) < >好的,所以我现在正在尝试编译一些东西,我对C++是新的,所以代码本身可能会导致错误,但是Eclipse正在显示的代码本身中没有红色标记出现。,c++,compiler-errors,mingw,eclipse-juno,C++,Compiler Errors,Mingw,Eclipse Juno,下面是错误说明 c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:128:7: 错误:指定只读引用“\uu a” c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:129:7: 错误:分配只读引用“\uu\b” 对我需要做什么有什么想法吗?在Wi7上,使用Eclipse Juno与MingwCC C++ 这是我正在编译的东西,我添加的唯一新东西是有人告

下面是错误说明

c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:128:7: 错误:指定只读引用“\uu a”

c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:129:7: 错误:分配只读引用“\uu\b”

对我需要做什么有什么想法吗?在Wi7上,使用Eclipse Juno与MingwCC

C++ 这是我正在编译的东西,我添加的唯一新东西是有人告诉我用于排列程序的“交换”东西

更新 置换

 #include <iostream>   // for cout
#include <cstdio>     // for printf()
#include <sstream>    // for stringstream
#include <stdio.h>
#include <string.h>
#include "Permutation.h"
using namespace std;

Permutation::Permutation() {
    /* nothing needed in the constructor */
}

void Permutation::permute(string str) {

    int low = 0;
    int high = str.length();
        int j;
        if (low == high) {
            cout << str << endl;
        } else {
            for (j = low; j <= high; j++) {
            std::swap(str[low], str[j]);
            permute(str, low + 1, high);
            std::swap(str[low], str[j]);
        }
        }
    }


void Permutation::permute(string str, int low, int high) {
//  int j;
//  if (low == high) {
//      cout << str << endl;
//  } else {
//      for (j = low; j <= high; j++) {
//          std::swap(str[j + low], str[j + j]);
//          permute(str, low + 1, high);
//          std::swap(str[j + low], str[j + j]);
//      }
//  }
}

找出了如何正确地交换它

int low = 0;
int high = str.length() - 1;
// make sure the string is a permutation and not a partial mix.
if (low == high) {
    cout << str << endl;
} else {
    //Takes each initial letter, then permutes the remaining string. Then moves to next character.
    for (int i = low; i <= high; i++) {
        std::swap(str[low], str[i]);
        permute(str, low + 1, high);
        std::swap(str[low], str[i]);
    }

}
int-low=0;
int高=str.length()-1;
//确保字符串是置换而不是部分混合。
如果(低==高){

我用C++重写了链接到的C代码:

// this method should be private or protected because
// str is passed by reference and will be modified !
// if you prefer a free standing function, don't add the
// declaration to the header, this for internal use only
void do_permute(std::string& str, unsigned i, unsigned n) {
    // you COULD pass str by value here, which
    // would remove the need to backtrack.
    // however, it would create a new copy for every
    // iteration which is terrible for performance,
    // especially with long strings.
    if(i==n)
        std::cout << str << '\n';
    else
        for(unsigned j=i; j<=n; ++j) {
            std::swap(str[i],str[j]);
            do_permute(str,i+1,n);
            std::swap(str[i],str[j]); // backtrack (undo swap)
        }
}

// this is the public method;
// pass string by value (copy), to allow do_permute()
// to modify the string.
void permute(std::string str, unsigned i=0, unsigned n=0) {
    if( n >= str.length() )
        return; // prevent out of bounds access
    // if n is 0 (default value) use the string length instead
    do_permute(str, i, n ? n : (str.length()-1) );
}

int main() {
    permute("BAR");
    permute("FO0BAR", 3);    // FOO***
    permute("FO0BAR", 0, 2); // ***BAR
}
//此方法应该是私有的或受保护的,因为
//str通过引用传递,将被修改!
//如果您喜欢独立函数,请不要添加
//声明到标头,此声明仅供内部使用
void do_permute(std::string&str,无符号i,无符号n){
//您可以在这里按值传递str,这
//这将消除回溯的需要。
//但是,它会为每个用户创建一个新副本
//迭代对性能非常不利,
//尤其是长弦。
如果(i==n)

std::难道不能交换常量字符串的两个字符吗。@克里斯,我想做类似str[j]的事情吗我想这就是C++的子串。或者我需要做些别的事情吗?看看大图,我至少能得到一些正确的东西。谢谢编辑:等等,我已经做了…现在我不想改变原来的字符串,只要你需要修改参数,就把它传给你。这样,你就可以得到一个拷贝了。修改并保持原稿不变。@克里斯,这是我的问题,我觉得……最初我需要使用字符串,但是我试图遵循的帖子使用了字符,所以我的思维混乱。下面是我要做的,我应该放弃它吗?如果是,你注释掉的应该与文章中的一样您将
const string&
更改为
string
@Anonymouse Coward您好!谢谢您的回答,我也终于能弄明白了。问题,您能为我解释一下这一行的逻辑吗,以便学习吗?谢谢
do_permute(str,I,n?n:(str.length()-1))
@Austin调用它。在上面的示例中,它转换为:如果n为非零
if(n)
求值为n,否则求值为(str.length()-1)。或者一般来说:
variable=condition?value\u if\u true:value\u if\u false
。请注意,value\u if\u true和value\u if\u false必须是同一类型!(你不能混音,比如说双音和弦乐)。
int low = 0;
int high = str.length() - 1;
// make sure the string is a permutation and not a partial mix.
if (low == high) {
    cout << str << endl;
} else {
    //Takes each initial letter, then permutes the remaining string. Then moves to next character.
    for (int i = low; i <= high; i++) {
        std::swap(str[low], str[i]);
        permute(str, low + 1, high);
        std::swap(str[low], str[i]);
    }

}
// this method should be private or protected because
// str is passed by reference and will be modified !
// if you prefer a free standing function, don't add the
// declaration to the header, this for internal use only
void do_permute(std::string& str, unsigned i, unsigned n) {
    // you COULD pass str by value here, which
    // would remove the need to backtrack.
    // however, it would create a new copy for every
    // iteration which is terrible for performance,
    // especially with long strings.
    if(i==n)
        std::cout << str << '\n';
    else
        for(unsigned j=i; j<=n; ++j) {
            std::swap(str[i],str[j]);
            do_permute(str,i+1,n);
            std::swap(str[i],str[j]); // backtrack (undo swap)
        }
}

// this is the public method;
// pass string by value (copy), to allow do_permute()
// to modify the string.
void permute(std::string str, unsigned i=0, unsigned n=0) {
    if( n >= str.length() )
        return; // prevent out of bounds access
    // if n is 0 (default value) use the string length instead
    do_permute(str, i, n ? n : (str.length()-1) );
}

int main() {
    permute("BAR");
    permute("FO0BAR", 3);    // FOO***
    permute("FO0BAR", 0, 2); // ***BAR
}