Given n numbers, find out the least k numbers from them
I assume you can use C++11.


Use initializer lists:

std::vector&lt;int&gt;nums;
nums.push_back(56);
nums.push_back(5);
nums.push_back(6);
nums.push_back(60);
nums.push_back(-6);
nums.push_back(3);
nums.push_back(600);


becomes

std::vector&lt;int&gt; nums = {56, 5, 6, 60, -6, 3, 600};

Use range based for:

nums = getKLeastNumbers(nums, 1);

for(int i=0; i&lt;nums.size(); i++)
{
    std::cout&lt;&lt;nums.at(i)&lt;&lt;std::endl;
}


becomes

for (auto &amp;i : getKLeastNumbers(nums, 1))
    std::cout &lt;&lt; i &lt;&lt; '\n';

Do not hide bugs. If you detect that someone used your function wrong tell them instead of letting them wonder why the return value doesn't make sense.

if(k&lt;=0 || k &gt; nums.size())
{
    return tmpNums;
}


becomes

assert(k &lt;= 0 &amp;&amp; k &gt; nums.size());


or

if (k &lt;=0 || k &gt; nums.size())
    throw std::range_error("k must be bigger than 0 and less than num's size");

You seem to be using the heap functions correctly, however, there are functions more suitable for that. I would pick std::partial_sort.

std::vector&lt;int&gt; getKLeastNumbers(std::vector&lt;int&gt; &amp;nums, int k)
{
    std::partial_sort(std::begin(nums), std::begin(nums) + k, std::end(nums));
    return { std::begin(nums), std::begin(nums) + k };
}

The declaration for getKLeastNumbers is a bit strange. nums is not const and gets modified which feels unexpected. Why can I not use getKLeastNumbers on a const std::vector?. I would prefer a const &amp; to preserve the original value, allow const vector and to be able to initialize nums with an initializer list directly.