|
-
March 15th, 2009, 07:15 AM
#1
stringtest.exe has stopped working
HI
I'm getting the runtime error as above when running very simple C++ progs.
I have a very simple test program as follows. It gives me the error. Note there are three pairs of calls to the functions 'm_setvalues' and 'm_gettitle'. If I delete a pair of these the program runs OK.
I can get similar behaviour playing with vectors.
Any ideas welcome.
#include <conio.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <string>
using namespace std;
// A vector based class to contain our items
class c_books {
public:
string m_title;
string m_author;
int m_price;
string m_isbn;
string m_gettitle();
void m_setvalues(string title, string author, int price, string isbn);
};
string c_books::m_gettitle()
{
cout << "Title = " << m_title << "\n";
cout << "Author = " << m_author << "\n";
cout << "Price = " << m_price << "\n";
cout << "ISBN = " << m_isbn << "\n";
};
void c_books::m_setvalues(string title, string author, int price, string isbn)
{
m_title = title;
m_author = author;
m_price = price;
m_isbn = isbn;
};
int main(){
// Create multimap
multimap <string, c_books> mapbooks;
// Create class
c_books ci_books;
// Populate class instance ci_books
ci_books.m_setvalues("blue Peter Annual 2001", "Val Singleton", 15, "2001ISBN");
// Out put title
ci_books.m_gettitle();
// Populate class instance ci_books
ci_books.m_setvalues("blue Peter Annual 2002", "Val Singleton", 15, "2002ISBN");
// Out put title
ci_books.m_gettitle();
// Populate class instance ci_books
ci_books.m_setvalues("blue Peter Annual 2003", "Val Singleton", 15, "2002ISBN");
// Out put title
ci_books.m_gettitle();
// Load object into multimap
mapbooks.insert (make_pair (ci_books.m_isbn, ci_books));
// Output map size
cout << "No of elements = " << mapbooks.size() << "\n";
getch();
}
-
March 15th, 2009, 07:57 AM
#2
Re: stringtest.exe has stopped working
c_books::m_gettitle() is declared to return a string but doesnt return anything.
Kurt
-
March 15th, 2009, 08:06 AM
#3
Re: stringtest.exe has stopped working
Kurt thank you soooo much. I hadn't expected such a strange runtime on - off error to be related to a coding issue relating to a declaration - when all worked with two calls but not three. I had checked the code carefully but clearly not enough experience to spot it.
I owe you a beer. Cheers
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|