C++ STL MAP DELETE,FIND관련해서 질문합니다

yoongun35795의 이미지

현재 controller, jobkorea Class를 이용하여 값을 입력받아 삭제와 검색을 할려고 합니다.

void controller::DeletejobKorea_Man()
{
	int seq;
 
	cout<<"삭제할 번호 입력 : "; cin>>seq;
	cout<<endl;
 
	m_job->DeleteMan(seq);
}

현재 controller.cpp 파일에 있는 DeletejobKorea_Man의 함수 내용입니다. 여기서 값을 입력받습니다.

그 다음 jobkorea의 deleteman 함수의 내용입니다.

void jobkorea::DeleteMan(int seq)
{
	std:map<int,Man*>::iterator itr;
 
	for(itr = m_mapMan.begin(); itr != m_mapMan.end(); itr++)
	{
		if(itr->first == seq)
		{
			m_mapMan.erase(itr);
		}
	}
	cout<<"해당 번호 없음"<<endl;
}

이렇게 입력한 seq를 넘겨받아 for문을 돌며 키값과 입력한 seq값이 같으면 삭제한다. 로 구성하고 싶은데

Debug Assertion Failed!

Program:...nts\visual studio

2010\projects\~\....

Expression:map/set iterator not increamentable

라고 시작하는 에러가 뜹니다..

뭐가 문제인지 모르겠습니다.

+추가로 Find에 관한 질문입니다.

void jobkorea::FindMan(Man* object)
{
	std::map<int,Man*>::iterator itr;
	std::map<int,Man*> m_mapMan;
	int seq;
 
	char name[20];
	char number[20];
	cout<<"찾을 번호를 입력하세요 : "; cin>>seq;
	cout<<endl;
 
	for(itr=m_mapMan.begin(); itr !=m_mapMan.end(); itr++)
	{
		if(itr->first == seq)
		{
			cout<<itr->second<<endl;
		}
	}
	return;
}

현재 Findman함수를 이렇게 작성하였는데 어디가 문제인지 뭐가 문제인지 알려주셨으면 감사하겠습니다.

kukyakya의 이미지

DeleteMan()은 왜 직접 iteration하시나요? 다음과 같이 쓰시는것이 더 간단합니다.

http://en.cppreference.com/w/cpp/container/map/erase

void jobkorea::DeleteMan(int seq)
{
	m_mapMan.erase(seq);
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.