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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:07:39+00:00 2026-06-13T19:07:39+00:00

This has been giving me trouble for some time now and no adjustments I

  • 0

This has been giving me trouble for some time now and no adjustments I make to the code seem to make a difference.
I am attempting to locate the digits in a line of text read from a file, and store said digits into another string to be used later. the initial copying seems successful, but when attempting to output the string the digits are stored in, the only output is a blank line.

Here is the code and included header files:

#include<iostream>
#include<string>
#include<fstream>
#include<cctype>

using namespace std;

int main()
{
    ifstream inFile;
    string temp;
    short count = 0;
    char fileName[20];  
    string info1;

    cout << "Enter the name of the file to be used: " << endl;
    cin >> fileName;

    inFile.open(fileName);

    if(!inFile)
    {
        cout << "Error opening file." << endl;      
    }
    else
    {           
        getline(inFile, info1);
        cout << info1 << endl;

        for(short i = 0; i < info1.length(); i++)
        {
            if(isdigit(info1[i]))
            {   
                temp[count] = info1[i];
                cout << temp[count] << endl;
                count++;
            }
        }
        cout << temp << endl;
    }   
    inFile.close();
    return 0;
}

And the output is as follows:

Enter the name of the file to be used:
input.txt
POPULATION SIZE: 30
3
0

Evidently, it is not outputting temp as expected.
Any assistance or advice would be 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-13T19:07:40+00:00Added an answer on June 13, 2026 at 7:07 pm

    Use this,
    temp+=info1[i];
    instead of
    temp[count] = info1[i];

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

Sidebar

Related Questions

This has been giving me pain for some time. I know Prism injects views
This has been bothering me lately- when I use some code like below to
I was doing some stuff with palindromes: This number 9966006699 has been giving me
I have a linq union statement that has been giving me some trouble and
This problem has been giving me headaches for a while now. My app operates
A php script is giving this array (which has been passed through json_encode() )
this has been an ongoing problem with me, ive been trying to make a
This has been frustrating me for a while now. I started developing a site
This has been driving me nuts for a week now. I have a class
I'm sure that this has been asked MANY times before, but it's still giving

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.