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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:11:30+00:00 2026-06-07T02:11:30+00:00

There are about 50 files that need to be opened in my program for

  • 0

There are about 50 files that need to be opened in my program for reading and i renamed all of them from 1.txt to 50.txt hoping i can pass the filename through a loop that increments the file number, but i don’t know how / don’t think it is possible to pass an integer to the char or is there a better way to workaround my situation.

char* filename = "";

for(int i =0; i < 50; i++)
{
if(i == 0){filename = "0.txt";}
if(i == 1){filename = "1.txt";} // ..
int num = 0, theinteger = 0;
ifstream in(filename, ios::binary);
unsigned char c;
while( in.read((char *)&c, 1) )
{       
        in >> theinteger;
        sca.chac[num]=theinteger; 
        num++;
}
}

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-06-07T02:11:32+00:00Added an answer on June 7, 2026 at 2:11 am

    There is a relatively straightforward way to do it – in C, use sprintf function, like this:

    char filename[100];
    sprintf(filename, "%d.txt", i);
    

    In C++, use ostringstream:

    ostringstream oss;
    oss << i << ".txt";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although there are a lot of posts about .net config files, I believe that
So, there seems to be a few questions asking about removing files/directories matching certain
I'm using encryption in my program, that decrypts files if it needs to use
How do I go about securing files that are stored on the server? We
I'm working on a C library that reads tag information from music files. I've
I have several (27) huge (several GB each) bz2 archive files that I need
I understand that there are many existing questions about Django template images, but I
I have this problem: I have a collection of small files that are about
I have potentially large files that need to be sorted by 1-n keys. Some
I'm trying to write a program that merge two or more .dat files in

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.