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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:42:18+00:00 2026-06-14T07:42:18+00:00

I have a method that that creates a MatLab array name from a file

  • 0

I have a method that that creates a MatLab array name from a file path and returns it as a std::string. the resulting string is passed into another method that writes the name to the file. When I try to get the length of the passed in string, it displays 0 when the length of the string is 12 or 13 chars.

My code:

bool MyClass::masterMethod(std::string fileURI){

 FILE* dataStream;
 // Assume dataStream is set up correctly

 // Get arrayName from File URI
 std::string arrayName = this->makeArrayNameFromPath( fileURI);

 //Write array name to file
 this->writeArrayName(arrayName , dataStream)



}


std::string MyClass::makeArrayNameFromPath(std::string filePathURI){


std::string tempString = filePathURI.substr(filePathURI.find_last_of('/')+1); 

std::string returnString = "";

long index = 0;

for(long i = 0; i < tempString.length(); i++){

    if((tempString[i] != ' ') && (tempString[i] != '.')){

        returnString[index++] = tempString[i];
    }
}

return returnString;

}



void MyClass::writeArrayName(std::string name , FILE *nameStream){

 // long testLength = name.length();
 // long testLength2 = name.size();
 // const char* testChar = nam.c_str();
 // long testCharLen = strlen(testChar);    

// The size of the name is the number of Chars * sizeof(int8_t)
int32_t sizeOfName = (int32_t)(name.length() * sizeof(int8_t));
int32_t nameType = miINT8;

fwrite(&nameType , sizeof(int32_t) , 1 , nameStream);
fwrite(&sizeOfName, sizeof(sizeOfName), 1, nameStream);
fwrite(&name , sizeof(name[0]), sizeOfName , nameStream);   

}

So I’m not sure why string::length is not working. If a create a std::string test = name, and print it , I can get the value of the string but can not get its length or size.
If I use const char* testName = name.c_str(); long test = strlen(testName), I get a the
correct value, but thought that wasn’t necessary.

So any advice or suggestion is appreciated.

  • 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-14T07:42:20+00:00Added an answer on June 14, 2026 at 7:42 am

    returnString[index++] = tempString[i]; doesn’t do what you think it does. It’s not adding additional space or length to the string, only overwriting memory at a location that the string doesn’t actually own. I think returnString.append(1, tempString[i]) or similar should do it.

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

Sidebar

Related Questions

I have a method that creates a MessageDigest (a hash) from a file, and
I have a method that creates a DLL from a .cs file that is
In my project I have a method that creates a string from integers (using
I have a method that creates a form in my controller: ... sbReturn.Append(String.Format(<p id='planSetupAddNewEffectiveDate'>));
Problem: I have a method that creates a list from the parsed ArrayList. I
I have the following method that creates and returns markup for my pagination links
I have a method that creates a dictionary from NSJSONSerialization class. I then enumerate
So I have a method that creates a text element based on an array
I have made this method that creates a 2D array for co-ordinates and places
I have a method that creates a local textfield and pops up the keyboard

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.