random shuffle이 안되는데 이유를 모르겠습니다.
1244
작성한 질문수 34
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Cents
{
private:
int m_cents;
public:
Cents(int cents = 0) { m_cents = cents; }
int getCents() const { return m_cents; }
int& getCents() { return m_cents; }
friend std::ostream& operator << (std::ostream& out, const Cents& cents)
{
out << cents.m_cents;
return out;
}
};
int main()
{
vector<Cents> arr(20);
for (unsigned i = 0; i < 20; ++i)
{
arr[i].getCents() = i;
}
std::random_shuffle(begin(arr), end(arr));
for (auto& e : arr)
{
cout << e << " ";
}
cout << endl;
return 0;
}
강의 내용 그대로 친 것 같은데 random 셔플부분만 std에 존재하지 않는다고 계속 에러나네요.
답변 2
0
안녕하세요?
random_shuffle은 seed를 지정해주지 않아도 된다는 점에서 shuffle보다 편리합니다만, C++ 17 이후에서는 사용할 수가 없습니다. shuffle 사용법은 아래 코드나 위 링크의 예제를 참고하시면 됩니다. (거의 동일합니다.)
추가로 본 질문은 영상 내부에서 자막으로 보충될 예정입니다.
// shuffle algorithm example
#include <iostream> // std::cout
#include <algorithm> // std::shuffle
#include <array> // std::array
#include <random> // std::default_random_engine
#include <chrono> // std::chrono::system_clock
using namespace std;
class Cents
{};
int main() {
vector<Cents> arr(20);
// ...
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(begin(arr), end(arr), std::default_random_engine(seed));
// ...
return 0;
}
0
https://en.cppreference.com/w/cpp/algorithm/random_shuffle
c++ 17 이후 부터는 사라졌다는군요.
우측의 solution explore 에서 project_name 우클릭-> properties-> C/C++ - > language -> C++ Language standard를 바꿔보세요.
변수가 메모리에 저장되는 것을 알려주는 강의가 어떤강의였죠
1
465
1
메모리 주소 10진수로 출력
1
653
1
클래스 템플릿 특수화에서 boolalpha로 표현된 리턴값에 대해 질문이 있습니다.
1
498
1
여러가지 리턴 타입에 관한 강의가 어떤 걸까요?
1
534
1
메모리 주소에 관한 질분
0
679
1
인터페이스 클래스에서 reportError의 매개변수에 대해 궁금한 것이 있습니다.
0
549
1
형변환 오버로딩에서 const 관련 질문이 있습니다.
0
443
1
Digit 뒤에 reference를 사용하는 이유
0
510
1
4.2 전역 변수, 정적 변수, 내부 연결, 외부 연결
0
322
1
dat파일이...
0
538
1
TODO:대입 연산자 오버로딩에 대한 소스코드입니다.
0
643
1
복사 생성자 관련 질문이 있습니다.
0
454
1
수업 중 궁금한점이 있습니다.
1
389
1
라이브러리자체가 이해가 되지 않습니다.
0
561
1
마지막 예제 질문
0
302
1
증감연산자 위치에 따른 수행 순서 질문입니다.
0
374
1
단항 연산자 오버로딩에서 return 부분에 질문이 있습니다.
1
410
1
friend함수 관련 질문이 있습니다.
0
311
1
operator+ 정의부분에서 궁금한 것이 있습니다.
0
447
1
3분 17초 질문
0
350
1
함수에 값을 대입한다는 개념이 이해가 되지 않습니다.
0
447
1
int getvalue() const에서 const는 왜 뒤에 붙는건가요?
0
443
2
const Something &st에서 const를 빼면 안되나요?
0
300
1
friend함수는 다른 클래스의 멤버함수로 쓸 수 없나요??
1
492
1





