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

  • SEARCH
  • Home
  • 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 8978923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:43:21+00:00 2026-06-15T19:43:21+00:00

I am trying to learn C++ by converting some programs I wrote in java.

  • 0

I am trying to learn C++ by converting some programs I wrote in java. One is an encryption program that takes text input and makes it look like DNA ( AGCTGTGCT… ). I can encrypt 64 characters using 256 codons of 4 bases each. ( “A” = “TGGC”, “B” = “ATGC”…) In java, I make a hashmap<String, String[]> where the key is the character to be encrypted and the value is an array of 4 strings, where each string is a codon that is chosen at random to replace the encrypted character.

In C++ I am trying to use a map to do the same thing, but it gives an error I just don’t understand. Here is the code where I try to make the codon table:

// iterate through the characters and select 4 codons from the list
for(int i = 0; i < 64; i++){
    codonTable[charList[i]][0] = originalCodonList[4 * i];
    codonTable[charList[i]][1] = originalCodonList[4 * i + 1];
    codonTable[charList[i]][2] = originalCodonList[4 * i + 2];
    codonTable[charList[i]][3] = originalCodonList[4 * i + 3];

    }
}

charList is the array that holds the 64 encodable characters ( they are really strings ) and originalCodonList is a string array that contains the 256 codons. I’ve tried several ways to assign 4 codons to the string array in the map, but nothing really seems to work. This generates the least error spam. Here is the output when I compile it:

In file included from /usr/include/c++/4.6/map:61:0,
from Genencrypt.cpp:4:
/usr/include/c++/4.6/bits/stl_map.h: In member function ‘std::map<_Key, _Tp, _Compare, >_Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) >[with _Key = std::basic_string, _Tp = std::basic_string [4], _Compare = >std::less >, _Alloc = std::allocatorstd::basic_string, std::basic_string [4]> >, std::map<_Key, _Tp, _Compare, >_Alloc>::mapped_type = std::basic_string [4], std::map<_Key, _Tp, _Compare, >_Alloc>::key_type = std::basic_string]’:
Genencrypt.cpp:63:25: instantiated from here
/usr/include/c++/4.6/bits/stl_map.h:453:11: error: conversion from ‘int’ to non-scalar type >‘std::map, std::basic_string [4]>::mapped_type {aka >std::basic_string [4]}’ requested

Of course google tells me it’s too long when I copy it into google. I’m not an expert in java, and I am much much better at java than at c++.

TL;DR: I want to make a map<string, string[]> in c++, is it possible and how to do it?

EDIT: Here is how I fixed it, I changed codonList from map<string. string[]> to map<string, vector<string> > and used this code to add the codons

    for(int i = 0; i < 64; i++){
    codonTable[charList[i]].push_back(originalCodonList[4 * i]);
    codonTable[charList[i]].push_back(originalCodonList[4 * i + 1]);
    codonTable[charList[i]].push_back(originalCodonList[4 * i + 2]);
    codonTable[charList[i]].push_back(originalCodonList[4 * i + 3]);
    std::cout << "Working?" << std::endl;
    }
  • 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-15T19:43:23+00:00Added an answer on June 15, 2026 at 7:43 pm

    The problem is that you cannot use C-style arrays in standard library containers, because they do not meet certain requirements such as being assignable and copy constructible. However, you can use the std::array container if you know the size of the array at compile time, or an std::vector if not:

    #include <map>
    #include <array>
    #include <vector>
    
    std::map<std::string, std::array<std::string, 4>> m_fixed;
    std::map<std::string, std::vector<std::string>> m_dynamic;
    

    Note that std::array is part of C++11. If you don’t have C++11 support, you may use the TR1 version std::tr1::array from the <tr1/array> header, or the Boost library version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to learn Ruby by converting a Java program to Ruby, but
Trying to learn backbone. In several applications that I've looked at (here is one
I'm converting an old AS2 file into AS3 (and trying to learn AS3 at
I am trying to learn web programming in python. I am converting my old
im trying to learn delegates and events in c#, i understand that an event
I'm trying to learn emacs elisp and trying to write a little program to
Trying to learn jquery here so I took a regular javascript snippet that loops
Trying to learn some R after doing mostly Haskell for rather a long time
I am a PHP/Mysql programmer trying to learn Java and I'm stuck on how
Trying to learn some F# and I've run into a couple of hangups. Here's

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.