HI。私の質問の前に、同じエラーで他のスレッドを調べましたが、何も私のために働いていませんでした。 私の問題コードはin >> a.name >> a.extension;
です。私が自分でテストしたように、タイプをstring
からchar
に変更しても機能しますが、string
タイプの値で動作させることはできません。エラーC++ 2679(バイナリ '>>': 'const std :: string'型の右オペランドを取る演算子が見つかりません(または受け入れ可能な変換はありません))
何か間違っていますか? compillation(Visual Studioの2015)
エラーC2679バイナリ「>>」に関する完全なエラーコードの下 :右側にタイプの「constのはstd ::文字列」 オペランドを取り全くオペレータが見つからない(または、そこにあります許容できない 換算)
ありがとうございます。
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class Soft {
private:
int *size;
time_t *dateTime;
public:
string name;
string extension;
Soft();
Soft(string, string);
Soft(const Soft&source);
~Soft();
friend istream& operator>> (istream& in, const Soft& a)
{
in >> a.name >> a.extension;
return in;
};
void changeName(string);
void changeExtension(string);
};
Soft::Soft() {
size = new int;
*size = 0;
name = string("");
extension = string("");
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::Soft(const Soft&source) {
name = source.name;
extension = source.extension;
size = new int;
*size = *source.size;
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::Soft(string a, string b) {
name = a;
extension = b;
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::~Soft() {
delete[] size;
delete[] dateTime;
}
void Soft::changeExtension(string a) {
extension = a;
}
void Soft::changeName(string a) {
name = a;
}
int main() {
Soft a;
getchar();
getchar();
return 0;
}
私はどちらも見えませんが、私の学校の先生はポインタですべてを求めています...すべての変数のポインタを明示的に使用しています –
@Eugen:それはばかげている。あなたはそれを間違って行う方法を教えられています。 : –
@LightnessRacesinOrbit:「可変」キーワードは教えられていないのですか?彼はメンバーデータを変更可能と宣言してから、彼の例はうまく動作します – Raindrop7