mingwCC 编译错误 (Eclipse Juno)
mingwCC compile error (Eclipse Juno)
好的,所以我现在正在尝试编译一些东西,我是C++新手,所以也许代码本身导致了错误,但是Eclipse向我展示的代码本身中没有红色标记。
这是错误所说的
C:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:128:7: 错误:只读引用"__a"的分配
C:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:129:7: 错误:只读引用"__b"的分配
关于我需要做什么的任何想法? 在Win7上,使用Eclipse Juno与MingwCC C++
这是我正在编译的内容,我添加的唯一新内容是有人告诉我用于我的排列程序的"交换"东西。
更新Permutation.cc
#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]);
// }
// }
}
排列.h
#pragma once
#include <string>
using namespace std;
class Permutation {
public:
Permutation();
void permute (string);
void permute (string, int, int);
private:
/* attemp to solve this problem without adding
* any instance variables/data members, but
* you may add private helper function members
* as many as you need */
};
main.cc
#include "Permutation.h"
int main()
{
Permutation p;
p.permute ("Permute");
p.permute ("--*--", 2, 3);
}
我重写了你在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
}
想出了如何正确交换它。
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]);
}
}
相关文章:
- 无法在Ubuntu上将共享库与Eclipse链接
- Eclipse CDT:单个项目中有多个C++文件
- C++ 运行时链接器错误 (liblog4cpp.so.5) Eclipse
- 标准库未在 Eclipse Juno 中解析
- Eclipse (Juno) CDT 索引器:"Error while parsing..." Makefile 项目
- mingwCC 编译错误 (Eclipse Juno)
- Win7中的Eclipse CDT(Juno):在PATH中找不到g++,iostream未解析和其他有趣的东西
- Eclipse Juno C++与microsoft 2010 C++express不创建EXE文件
- Qt with Eclipse CDT Juno
- 无法使用std=C++11设置Eclipse Juno C++
- eclipse cdt juno c++
- c++ eclipse juno build error
- Eclipse CDT Juno - 工具链问题
- 在Eclipse Juno ADT中启用c++ 11符号解析
- C++ 在 Mac 上使用 Eclipse Juno - "binary not found"
- 带有 CDT 的 Eclipse Juno 不添加内置的包含目录
- Undefined Reference to .. - mingw - winxp - eclipse juno
- Configuring Eclipse Juno for C++
- 我该如何使用eclipse juno(最新版本)的编译器
- Issue with eclipse juno for c,c++ in windows