R6010 -abort() has been called

Hi all and thanks in advance for any help that you may bring. I'm an avid reader of this site and use it daily to help advance my learning. I'm running into quite the trouble with this program I'm writing for school. As you can see from the topic I'm receiving this error message. "R6010 -abort() had been called" I believe I'm getting it from either a memory issue or something related to the two files I'm using, one to read and one to write to.

I'll post my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//Lab2_Vector Names
/*
Stage 1:
Create a vector of strings of various names like  Smith, Joseph ( last name first) 
(about 10 is enough)
Initialize manually.
Next sort the list in reverse alphabetical order using a function to describe the sort in the 
sort function from the **algorithm** library.

Stage 2:
Get the strings for the vector from a file ( remember that the input file must be a **resource** 
in Visual Studio).
Sort it as above and then write back to same file so it is overwritten with the sorted data.

Extra Credit.
Change the input file to add a tab and then a score between 1 and 100.
Change the function that governs the vector sort to sort by the scores rather than names.
Output the sorted data back to the file so that the lines are properly sorted so the name of 
the highest score is on top etc.
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
using namespace std;
bool sorting(string a, string b);//sort function

int main()
{
	vector<string> name;
	string filename="myfile.txt";
	/*
	name.push_back("Cefalo, Joseph	100");
	name.push_back("Marin, Alexa	097");
	name.push_back("Loftus, Jay	043");
	name.push_back("Pehl, Kaila	025");
	name.push_back("Cefalo, Dunkin	088");
	name.push_back("Marin, Cody	054");
	name.push_back("Bond, James	067");
	name.push_back("Ketchum, Ash	071");
	name.push_back("Kline, Stacey	006");
	name.push_back("Rogers, Emily	016");
	*/
	

	ifstream fin;
	fin.open(filename); //open read file
	if(fin.fail())
	{
		cout << "Input File Not Opened." << endl;
		exit(1);
	}
	string temp;
	while(getline(fin, temp))
	{
		name.push_back(temp);
	}
	fin.close(); //end of read file

	
	sort(name.begin(), name.end(), sorting); //sorting of vector

	
	ofstream fout;
	//string filename="finalfile.txt";
	
	fout.open(filename); //open write file

	if(fout.fail())
	{
		cout << "File Failed to Open." << endl;
		exit(0);
	}
	for(unsigned int i=0; i<name.size(); i++)
	{
		if(i==name.size()-1)
			fout << name[i];
		else
			fout <<	name[i] << endl;
	}
	fout.close(); //end of write file

	fout << "-------------------" << endl;
	fout << "Writing to File. Check 'finalfile.txt' for Completion";
	return 0;
}
bool sorting(string a, string b)//Sorting
{
	a=a.substr(a.find('\t')); //find tab and make substring
	int y=atoi(a.c_str()); //output as c-string
	b=b.substr(b.find('\t'));//find tab and make substring
	int z=atoi(b.c_str());//output as c-string
	return y>z;
}


There's many edits done to this code and sections commented out as they were only for testing. The issue I'm running into is I need to read the file name "myfile.txt" which looks exactly like this:
Cefalo, Joseph 100
Marin, Alexa 97
Loftus, Jay 43
Pehl, Kaila 25
Cefalo, Dunkin 88
Marin, Cody 54
Bond, James 67
Ketchum, Ash 71
Kline, Stacey 16
Rogers, Emily 06

Once reading them into the vector it's supposed to sort them by number highest to lowest and write to file named "finalfile.txt"

It reads the file as I dont get an error from it however it gives me the error upon trying to write and aborts.

I'm sure I'm missing something here as I'm a noob.

Thanks for any help.
It would fail in `sorting()' if the string does not have a TAB character.
That is the case of `Marin, Alexa 97'

> it's supposed to sort them by number highest to lowest and write to file named "finalfile.txt"
you are writing to `myfile.txt'
Last edited on
ne555 saying i love you would be an understatement. I knew it was something so minute that was causing the error. You are absolutely correct. Nice catch on the error of the tab. And yes I had commented out the "finalfile.txt" through all of my testing. Sometimes I go so crazy trying to test and retest and I forget to put stuff back in.

As a new programmer the abort error was making me nuts as I didn't know why or how to fix it as there were no build errors.

Thanks for the second pair of eyes and your assistance. I've been staring at this code for almost 3 days trying diff ways over and over to fix it. Dummy me never checked the file.

Thanks again.
Topic archived. No new replies allowed.