好的,所以我現在想編譯一些東西,而我是C++的新手,所以也許代碼本身導致錯誤,但是Eclipse沒有顯示代碼本身顯示的紅色標記我。mingwcc編譯錯誤(Eclipse Juno)
下面是錯誤說
c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:128:7: error: assignment of read-only reference '__a'
c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:129:7: error: assignment of read-only reference '__b'
任何想法什麼我需要做什麼?在Win7上,使用Eclipse Juno for C++與MingwCC
下面是我正在編譯的內容,我添加的唯一新東西就是這個「交換」的東西,有人告訴我用於我的置換程序。
修訂 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]);
// }
// }
}
Permutation.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);
}
你不能換一個字符串常量的兩個字符。 – chris
@chris我想做類似str [j]的事嗎?我認爲這就是C++的子字符串。或者還有什麼我需要做的? 縱觀整體情況,我至少有點正確? 謝謝 編輯:等等,我已經這樣做了....現在我失去了 – Austin
如果你不想改變原始字符串,只需要通過值傳遞它,如果你需要修改參數。通過這種方式,您可以獲得一份副本進行修改,而原稿保持不變。 – chris