Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:00:17+00:00 2026-06-17T04:00:17+00:00

void Lexicon::buildMapFromFile(string filename ) //map { ifstream file; file.open(filename.c_str() ); string wow, mem, key;

  • 0
void Lexicon::buildMapFromFile(string filename )  //map
{
    ifstream file;
    file.open(filename.c_str() );
    string wow, mem, key;
    unsigned int x = 0;

    while(true) {
        getline(file, wow);
        if (file.fail()) break; //check for error
        while (x < wow.length() ) {
            if (wow[x] == ',') {
                key = mem;
                mem.clear();
                x++; //step over ','
            } else 
                mem += wow[x++];
        }

        list_map0.put(key, mem); //char to string
        list_map1.put(mem, key); //string to char
        mem.clear(); //reset memory
        x = 0;//reset index
    }
    file.close();
}

This function reads a 2-column csv file and creates a map of column2 with column1 as the key. I compiled with g++ and the file is on the university file share, when I run the program with ./foo the csv files [in the same directory folder as foo] are not read… why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:00:18+00:00Added an answer on June 17, 2026 at 4:00 am

    Perhaps you don’t have read permission from that file. Issue the command ls -l <csv_file>
    see if you have right to read from. For more information on file permissions refer to this link https://help.ubuntu.com/community/FilePermissions

    Try the following code works perfect for me

       #include <iostream>
    #include <stdio.h>
    #include <map>
    #include <string>
    #include <fstream>
    using namespace std;
    
    
    int main(void )  //map
    {
       map<string, string> list_map0;
    
       map<string, string> list_map1;
        string filename = "csv";
        ifstream file;
        file.open(filename.c_str() );
        string wow, mem, key;
        unsigned int x = 0;
    
        while(true) {
            getline(file, wow);
            if (file.fail()) break; //check for error
            while (x < wow.length() ) {
                if (wow[x] == ',') {
                    key = mem;
                    mem.clear();
                    x++; //step over ','
                } else
                    mem += wow[x++];
            }
    
            list_map0[key] = mem; //char to string
            list_map1[mem] = key; //string to char
            mem.clear(); //reset memory
            x = 0;//reset index
        }
        printf("%d\n", list_map0.size());
        file.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j
void slice_first_char(char ** string) { *string = &(*string[1]); } int main(int argc, char *
void display(char * str){ printf(%s: Missing file\n, str); } int main(int argc, char **argv)
void permute(string elems, int mid, int end) { static int count; if (mid ==
void updatebfile(char filename[MAX]) { fstream writereadb; char cont='y'; char filenameb [MAX]; int i=1; int
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void AFCQueue::ExtractValuesSecComplex(int startIndex, int endIndex,int helperIndex) { int size = 0,i,index; TimeType min_timestamp; bool

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.