사용자 입력을 기반으로 함수를 호출하려고합니다. 나는 내가 뭘 잘못하고 있는지 파악할 수 없다. 이 오류가 계속 발생합니다.사용자 입력을 기반으로 정렬 또는 병합합니다.
error: no matching function for call to 'sort(std::vector<int, std::allocator<int> >&)'
누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 제가 C++을 처음 접했을 때 철저히 제안 해주십시오. 당신은 당신이 그것을 호출하기 전에 sort
함수를 선언 할 필요가
#include <iterator>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iostream>
#include <string>
std::ifstream in("");
std::ofstream out("outputfile.txt");
std::vector<int> numbers;
std::string sortType = "";
std::string file = "";
int main()
{
std::cout << "Which type of sort would you like to perform(sort or mergesort)?\n";
std::cin >> sortType;
std::cout << "Which file would you like to sort?\n";
std::cin >> file;
//Check if file exists
if(!in)
{
std::cout << std::endl << "The File is corrupt or does not exist! ";
return 1;
}
// Read all the ints from in:
copy(std::istream_iterator<int>(in), std::istream_iterator<int>(),
std::back_inserter(numbers));
//check if the file has values
if(numbers.empty())
{
std::cout << std::endl << "The file provided is empty!";
return 1;
} else
{
if(file == "sort")
{
sort(numbers);
}else
{
mergeSort();
}
}
}
void sort(std::vector<int>)
{
// Sort the vector:
sort(numbers.begin(), numbers.end());
unique(numbers.begin(), numbers.end());
// Print the vector with tab separators:
copy(numbers.begin(), numbers.end(),
std::ostream_iterator<int>(std::cout, "\t"));
std::cout << std::endl;
// Write the vector to a text file
copy(numbers.begin(), numbers.end(),
std::ostream_iterator<int>(out, "\t"));
std::cout << std::endl;
}
void mergeSort()
{
//mergesort code..
}
너무 간단해서 거의 당황 스럽네요. 팁 주셔서 감사합니다! 확실히 이러한 변화를 일으킬 것입니다. – Jmh2013