mapping하는 다음 c++소스를 봐주세요.

jee89의 이미지

---------------
src.txt keystring | value string 1 | value string 2
와 같은 형식으로 10만건정도 들어가있고요.
map.txt에서 keystring | value string |
형식으로 200건 정도 mapping 기준데이터가 들어있습니다.
src.txt를 한줄씩읽어 첫번째 필드(keystring)를 키필드로
map.txt의 첫필드(keystring)과 매핑시켜 mapping된 map.txt의
value string을 가져오는 것인데요. find관련부분에서 에러가 나는것같에요.
에러좀 잡아주십시오. ( '|' 필드구분자)

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <map>

typedef stringconst_iterator iter;
map< string , string > m;
iter myfind( const string& str , iter b );
void loadmemory( );
int main()
{
loadmemory();

ifstream infile( "src.txt" ); //source file
ofstream outfile( "src.cpp.new" ); //mapped file
string line;
while ( getline( infile , line ) )
{
iter i , b = line.begin() , f;
string key;
i = myfind( line , b );
if ( f = m.find( key = string( b , i ) ) == m.end() )
{
cout << key << " mapping failed" << endl;
continue;
}
outfile << *f << string( i , line.end() ) << endl;

}
return 0;
}

iter myfind( const string& str , iter b )
{
iter i;
for ( i = b ; i < str.end() ; i++ )
if ( *i == '|' ) return i;
return i;
}

void loadmemory( )
{
string line , key , value;
ifstream infile( "map.txt" ); // mapping file( key string , value string)
while ( getline( infile , line ) )
{
iter i , b = line.begin();
i = find( b , line.end() , '|' );
key = string( b , i );
b = i + 1;
i = find( b , line.end() , '|' );
value = string( b , i );
m[key] = value;
}
}

pynoos의 이미지

jee89 wrote:
---------------
src.txt : keystring | value string 1 | value string 2
와 같은 형식으로 10만건정도 들어가있고요.
map.txt에서 keystring | value string |
형식으로 200건 정도 mapping 기준데이터가 들어있습니다.
src.txt를 한줄씩읽어 첫번째 필드(keystring)를 키필드로
map.txt의 첫필드(keystring)과 매핑시켜 mapping된 map.txt의
value string을 가져오는 것인데요. find관련부분에서 에러가 나는것같에요.
에러좀 잡아주십시오. ( '|' :필드구분자)


typedef string::const_iterator iter;
map< string , string > m;
iter myfind( const string& str , iter b );
void loadmemory( );
int main()
{
....
       iter i , b = line.begin() , f;
       string key;
       i = myfind( line , b );
       if ( f = m.find( key = string( b , i ) ) == m.end() )
       {
          cout << key << " mapping failed" << endl;
          continue;
       }
...                    
   return 0;
}

음..
= 보다 == 이 연산자가 높습니다. 의미하신 것이 m.end()를 만나지 않은
뭔가를 찾는 결과를 f 에 담으시려면 앞에 ( ) 를 묶어 줘야합니다.

그리고 m의 find 는 map<string,string>::iterator 를 돌려줄 것 같은데, string::const_iterator에 그 결과를 담는 다는 것이 이상하군요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.