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 6366711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:27:22+00:00 2026-05-25T00:27:22+00:00

I apologise for being a C++ novice. I am trying to learn by translating

  • 0

I apologise for being a C++ novice. I am trying to learn by translating some code from Java.

In this code, the strings that are read in represent letter frequencies in % in a language.

The test string we are dealing with is a10b10c10d10e10f50, as the test code shows.

In the loop below, the first 3 values (0.1, 0,1, 0.1) are correctly read in, as are the 5th and 6th (0.1 and 0.5), but for some reason the 4th value for letter ‘d’, when i is 9, is read in as 1000000000.0000000, according to the debugger in Visual Studio. Any ideas why?

#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <cmath>

using namespace std;

class SymbolFrequency {
public:
    double language(vector <string> frequencies, vector <string> text) {

        for (unsigned int fset = 0; fset < frequencies.size(); fset++) {
            double expected[26];
            fill(expected, expected + 26, 0.0);
            for(unsigned int i = 0; i < frequencies[fset].length(); i += 3) {
                char letter = frequencies[fset][i];
                istringstream is(frequencies[fset].substr(i + 1, i + 3));
                double freq;
                is >> freq; freq /= 100;
                expected[letter - 'a'] = freq;
            }
...

Test code:

int main() {
    SymbolFrequency s;
    const char *fargs[] = {"a10b10c10d10e10f50"};
    vector<string> f(fargs, fargs + 1);
    vector<string> t;
    t.push_back("abcde g");
    double d = s.language(f,t);
    cout << (d) << endl;
    cin.get();
    return 0;
}
  • 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-05-25T00:27:23+00:00Added an answer on May 25, 2026 at 12:27 am

    You’re not calling substr() correctly; try frequencies[fset].substr(i + 1, 2).

    (The reason for the strange value is that it parses 10e10 as 100 billion.)

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

Sidebar

Related Questions

if there is another question that explains this I apologize for not being able
I'm trying to write some code for simple complex number manipulation. I'm using a
I am very new to Java and Hibernate and after being taken from a
I apologise if there is a similar post to this that I haven't found,
Context I apologize for this question being soft / philosophical; it's a set of
I apologise if this is a bit dim but I want to send something
I apologise if any of this sounds like a broken record but I've trawled
I apologise if this has been asked before but I can't find the info
I apologise if this has been asked before or if it's now answerable. I'm
I am fairly new to this and I do apologise if this is a

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.