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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:06:16+00:00 2026-06-18T11:06:16+00:00

Small question. With a string that I converted from a text file using: std::string

  • 0

Small question. With a string that I converted from a text file using:

std::string content((std::istreambuf_iterator<char>(istr) ), 
                        (std::istreambuf_iterator<char>() ) );

Which when printed, looks like:

@....@........@......@....................@....@...............@..........@..@......
@....@..@@@...@......@.......@@@..........@....@..@@@....@@@...@..........@..@......
@@@@@@.@...@..@......@......@...@.........@....@.@...@..@......@.......@@@@..@......
@....@.@@@@...@......@......@...@.........@....@.@...@..@......@......@...@..@......
@....@.@......@......@......@...@.........@.@@.@.@...@..@......@......@...@.........
@....@..@@@@...@@.....@@.....@@@...........@..@...@@@...@.......@@.....@@@@..@......
....................................................................................

And yet, when I use this code here:

    for (int i = 0; i < (content.length()-6); i++){
        std::string w = content.substr(i, 6);
        std::cout << w << '\n';
    }

I get many substrings as I wanted, but they don’t look as I expected. My intent is to have something that looks like this (as an example for the first line):

@....@
......
..@...
...@..
......
......
......
@....@
......
......
...@..
......
..@..@
......

When instead, I get along the lines of:

@....@
....@.
...@..
..@...
.@....
@.....
......
......
......
.....@
....@.
...@..
..@...
.@....

I’m not sure why this could be, perhaps I think substr does something that it does not?
I just want to get the first 6 letters of the first line, then the next 6, and the next, and so on continuing onto the second line of the string.

Thanks for the help!

  • 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-18T11:06:17+00:00Added an answer on June 18, 2026 at 11:06 am

    I don’t actually know C++, but it looks like you’re making substrings (0, 5) then (1, 6) then (2, 7), etc. when you are trying to make substrings (0, 5) then (6, 11) then (12, 17).

    Try incrementing i by 6 instead of by 1 each time. So the new code would be

    for (int i = 0; i < (content.length()-6); i += 6){
            std::string w = content.substr(i, 6);
            std::cout << w << '\n';
        }
    

    The @ that is getting shifted over in your example is the same @ each time, because you are just snaking along by one character.

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

Sidebar

Related Questions

I've successfully set up a small XZ compressor which returns a std::string that contains
small question about C++ replace function. I'm parsing every line of text input line
hello I have a small question in objective-C memory management. I know that if
I am retruning a string from the webmethod that is a table. The success
After reading this beautiful question: Why is char[] preferred over String for passwords? ,
Hi Friends, I have a small question, I have a paragraph of string, now
I am making a small program using C++/CLI that use TcpListener , I know
The question How can I decode a string with JavaScript that's encoded in php
I have a small question regarding a Hash Table. Suppose i have a String
I have small question by entity framework 4.1. There is interface of image DTO:

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.