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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:01:43+00:00 2026-06-01T02:01:43+00:00

Im pulling a text file – it will be input by user currently its

  • 0

Im pulling a text file – it will be input by user
currently its just pulling from C:\Dump\test.txt
I want to re-arrange the words in said file

This is what i have so far

static string revFunc(string a)
{
    ifstream inp;
    inp.open(a, std::ios::in);
    string lines;

    while(getline(inp, lines)){
        istringstream iss(lines);
        string outstr;
        string word;
        iss >> outstr;
        if (inp >> word){
            outstr = word + ' ' + outstr + ' ';
            cout << outstr;

        }
    }return 0;
}

the string a is the path to file on the hdd
this will parse 2 lines backwards
there are ~13 lines in the tester file

this is from int main()

int main(){
string file;
int words = 0;
int lines = 0;
int choice;

system("cls");

cout << "Enter Filename: " << endl;
file = "C:\\Dump\\test.txt";
cout << file;
//cin >> file;

cout <<"MENU"<<endl;
cout <<"----------------------------------" << endl;
cout << "1. Count Words" << endl;
cout << "2. Count Lines" << endl;
cout << "3. Index Words" << endl;
cout << "4. Average Length of Words" << endl;
cout << "5. Print Text File to Screen" << endl;
cout <<"----------------------------------" << endl;
cout << "??: ";
cin >> choice;

switch(choice){

case 1: cout << "Words: " << wordFunc(file) << endl;
        system("PAUSE");
        break;
case 2: cout << "Lines: " << lineFunc(file, lines) << endl;
        system("PAUSE");
        break;
case 3: indexFunc(file);
        system("PAUSE");
        break;
case 4: cout << "Average Length: " << avgWordFunc(file) << endl;
        system("PAUSE");
        break;
case 5: printStrFunc(file);
        cout <<endl;
        system("PAUSE");
        break;
case 6: revFunc(file);
        cout << endl;
        system("PAUSE");
        break;

}

return 0;
}

Then the program aborts – im sure due to bad coding 🙂
Any help pointing out my ridiculous mistakes are 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-01T02:01:44+00:00Added an answer on June 1, 2026 at 2:01 am

    You say your refFunc returns a string, but the return value is 0 (an int, not a string).

    This will result in a problem as the program tries to use a string object, and finds “garbage” (that has been allocated in anticipation of a string but has not been filled with the correct bits of a string).

    To fix, you either need to change the return type to int or change the return value to a valid string (e.g. "").

    Alternatively, if you are not using the return value (as is the case in your example), you can change the return type to void. In this case, use only return; (note: no value after return), or you can leave the whole return statement out;

    NOTE: To prevent from future such mistakes, configure your compiler to compile with maximum warnings setting and possibly with warnings turned into errors. This will prevent you from compiling your program without at least the compiler telling you you are doing something (most likely) incorrectly

    NOTE: Do not learn the habit of using system() even for pausing your application. It is platform dependent, and can introduce a security risk (although I don’t think you will worry about that for a while)

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

Sidebar

Related Questions

I have a text file that I am pulling from my SD card which
I'm trying to display a Twitter feed by pulling from a cached text file
I am pulling info from an XML file and the div class=long works great
I'm pulling a simple jpg from the file system like so ... var objz
What I'm doing is working with a text document that I'm pulling numbers from
I need some help pulling cell data from table when a user clicks the
I've got a VBS file that is pulling XML from our website. It going
I have a CGI script pulling bibliography data from a BibTeX file, building HTML
I'm pulling in a xml-file with just one result in it. One of the
I'm currently puling data from an external XML file and converting it to JSON

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.