For a problem, I have to use dynamic allocation and functions (using pointer variables only) to read the names from the .txt file and sort the names in lexical order. However, I cannot even get the read function to work properly. This is what it wrote:
void readNames(std::string* a[])
{
std::ifstream fin;
fin.open("names.txt");
for (int i = 0; i < 7; ++i)
{
fin >> *(a[i]);
std::cout << *a[i];
}
}
This is how I called it in main:
std::string* names;
names = new std::string[7];
readNames(&names);
However, when I run this I get the error:
Exception thrown: read access violation. this was 0xCCCCCCCC.
And this function is displayed(not sure if this helps):
void _Check_offset(const size_type _Off) const { // checks whether _Off is in the bounds of [0, size()]
if (_Mysize < _Off) {
_Xran();
}
}
If anyone can help me with this I would relly appreciate it, thank you!