Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues, especially the pinned issues.
Exception report
Exception:
System.ArgumentOutOfRangeException: The value must
be greater than or equal to zero and less than the
console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left,
Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
PS C:\Users\vivek\OneDrive\Desktop\DSA-Final Notes>
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 139 Keys:
c d Space " c : \ U s e r s \ v i v e k \ O n e D
r i v e \ D e s k t o p \ D S A - F i n a l Space N o t e s \ C + + Space S T L \ " Space ; Space i f
Space ( $ ? ) Space { Space g + + Space t u t 2 _ V e c t o r . c p p Space - o Space t u t 2 _ V e c
t o r Space } Space ; Space i f Space ( $ ? ) Space { Space . \ t u t 2 _ V e c t o r Space } Enter
Exception:
System.ArgumentOutOfRangeException: The value must
be greater than or equal to zero and less than the
console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left,
Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
Screenshot
Environment data
#
Steps to reproduce
/*
-> Dynamic Memory Allocation
-> Vectors are dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators.
-> In vectors, data is inserted at the end. It increases the size of array by double when size limit is exceeded.
-> capacity :- total storage capacity which can be hold, total memory which can be assigned.
-> size :- total number of elements stored.
-> vector ex(50, 6) = {6, 6, 6, 6, 6, 6, 6, .......};
-> vector ex2[50] = this is an array of 50 vectors.
*/
#include
#include <bits/stdc++.h>
#include
using namespace std;
int main()
{
cout << endl;
vector<int> v;
cout << "Capacity of vector v -> " << v.capacity() << endl;
cout << "Size of vector v -> " << v.size() << endl;
// Inserting elements in vector
v.push_back(1);
cout << "Capacity of vector v -> " << v.capacity() << endl;
cout << "Size of vector v -> " << v.size() << endl;
v.push_back(2);
cout << "Capacity of vector v -> " << v.capacity() << endl;
cout << "Size of vector v -> " << v.size() << endl;
v.push_back(3);
cout << "Capacity of vector v -> " << v.capacity() << endl;
cout << "Size of vector v -> " << v.size() << endl;
cout << endl;
// Basic Operations :-
cout << "Element at 2nd Index-> " << v.at(2) << endl;
cout << "Empty or not-> " << v.empty() << endl; // returns 0 [false] or 1 [true]
cout << "First Element-> " << v.front() << endl;
cout << "Last Element-> " << v.back() << endl;
////////////////////////////////////////////////////////////////////////////////
cout << "-----------" << endl;
cout << "Before pop" << endl;
for (int i = 0; i < v.size(); i++)
cout << v[i] << endl;
v.pop_back(); // pop_back() function is used to pop or remove elements from a vector from the back. The value is removed from the vector from the end, and the container size is decreased by 1.
cout << "After pop" << endl;
for (int i : v)
cout << v[i] << endl;
/////////////////////////////////////////////////////////////////////////////////
cout << "-------------------" << endl;
cout << "Before clearing, size of vector v -> " << v.size() << endl;
v.clear(); // The clear() function is used to remove all the elements from the vector container, thus size will be 0. But the capacity remains the same.
cout << "After clearing, size of vector v -> " << v.size() << endl;
cout << "-------------------" << endl;
/////////////////////////////////////////////////////////////////////////////////
// Copying a vector in another vector
cout << "Copying a vector in another vector :-" << endl;
vector<int> vtr1 = {4, 2, 5, 7, 5, 12};
vector<int> vtr2(vtr1);
vector<int> vtr3 = vtr1;
vector<int> vtr4;
vtr4 = vtr1;
for (auto it : vtr1)
{
cout << it << " ";
}
cout << endl;
for (auto it : vtr2)
{
cout << it << " ";
}
cout << endl;
for (auto it : vtr3)
{
cout << it << " ";
}
cout << endl;
for (auto it : vtr4)
{
cout << it << " ";
}
cout << endl;
cout << "-------------------" << endl;
// Printing the entire vector and using Iterators
cout << "Printing the entire vector and using Iterators" << endl;
vector<int> printVtr = {3, 8, 6, 12, 3, 85, 1, 3, 4, 56, 6};
for (int i = 0; i < printVtr.size(); i++)
{
cout << printVtr[i] << " ";
}
cout << endl;
for (vector<int>::iterator it = printVtr.begin(); it != printVtr.end(); it++)
{
cout << *(it) << " "; // (*) required as it points to the memory and not the element.
}
cout << endl;
for (auto it = printVtr.begin(); it != printVtr.end(); it++)
{
cout << *(it) << " "; // (*) required as it points to the memory and not the element.
}
cout << endl;
for (auto it : printVtr)
{
cout << it << " ";
}
cout << endl;
cout << "-------------------" << endl;
// Erase Function uses:-
cout << "Erase Function uses" << endl;
vector<int> eraseVtr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (auto it : eraseVtr)
{
cout << it << " ";
}
cout << endl;
eraseVtr.erase(eraseVtr.begin() + 1); // (position)
for (auto it : eraseVtr)
{
cout << it << " ";
}
cout << endl;
eraseVtr.erase(eraseVtr.begin() + 2, eraseVtr.begin() + 6); // (start, end)
for (auto it : eraseVtr)
{
cout << it << " ";
}
cout << endl;
cout << "-------------------" << endl;
// insert function
cout << "Uses of Insert Function" << endl;
vector<int> insertVtr = {1, 2, 3, 4, 5};
for (auto it : insertVtr)
{
cout << it << " ";
}
cout << endl;
insertVtr.insert(insertVtr.begin() + 1, 100); // ( position, value)
for (auto it : insertVtr)
{
cout << it << " ";
}
cout << endl;
insertVtr.insert(insertVtr.begin() + 3, 2, 55); // ( position, occurrences, value)
for (auto it : insertVtr)
{
cout << it << " ";
}
cout << endl;
insertVtr.insert(insertVtr.begin(), vtr1.begin(), vtr1.end()); // inserting entire vector
for (auto it : insertVtr)
{
cout << it << " ";
}
cout << endl;
cout << "-------------------" << endl;
vector<int> swapVtr1 = {4, 2, 5, 7, 5, 12};
vector<int> swapVtr2 = {1, 12, 25, 37, 55, 12};
cout << "before swap" << endl;
for (auto it : swapVtr1)
{
cout << it << " ";
}
cout << endl;
for (auto it : swapVtr2)
{
cout << it << " ";
}
cout << endl;
swapVtr1.swap(swapVtr2);
cout << "after swap" << endl;
for (auto it : swapVtr1)
{
cout << it << " ";
}
cout << endl;
for (auto it : swapVtr2)
{
cout << it << " ";
}
cout << endl;
// sorting vector
vector<int> sortVec = {1, 7, 5, 3, 2, 12, 9, 6, 53, 62};
sort(sortVec.begin(), sortVec.end());
cout << "after sort" << endl;
for (auto it : sortVec)
{
cout << it << " ";
}
vector<int> sortReverseVec = {1, 7, 5, 3, 2, 12, 9, 6, 53, 62};
sort(sortReverseVec.begin(), sortReverseVec.end(), reverse);
cout << "after sort" << endl;
for (auto it : sortReverseVec)
{
cout << it << " ";
}
cout << endl;
return 0;
}