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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:50:10+00:00 2026-06-04T13:50:10+00:00

I want the console window that pops up whenever you run a C++ program

  • 0

I want the console window that pops up whenever you run a C++ program to stay… but in my code here that’s not happening. It just quickly vanishes. What’s wrong? Note: I am new to C++.

For some reason it works properly when I use only the main() function to hold everything and not have the second one, but for purposes of my assignment I can’t stuff everything in to main().

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;

ifstream file("maze.txt");
vector<char> vec(istreambuf_iterator<char>(file), (istreambuf_iterator<char>())); // Imports characters from file
vector<char> path;                      // Declares path as the vector storing the characters from the file
int x = 18;                             // Declaring x as 18 so I can use it with recursion below
char entrance = vec.at(16);             // 'S', the entrance to the maze
char firstsquare = vec.at(17);          // For the first walkable square next to the entrance
vector<char> visited;                   // Squares that we've walked over already

int main()
{
    if (file) {
        path.push_back(entrance);               // Store 'S', the entrance character, into vector 'path'
        path.push_back(firstsquare);            // Store the character of the square to the right of the entrance
                                                // into vector 'path'.
        while (isalpha(vec.at(x)))
        {
            path.push_back(vec.at(x));
            x++;
        }
    }
}

int printtoscreen()
{
    cout << "Path is: ";                    // Printing to screen the first part of our statement

        // This loop to print to the screen all the contents of the vector 'path'.
        for(vector<char>::const_iterator i = path.begin(); i != path.end(); ++i)  // 
        {
        std::cout << *i << ' ';
        }

        cout << endl;
        cin.get();                          // Keeps the black box that pops up, open, so we can see results.
        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-04T13:50:11+00:00Added an answer on June 4, 2026 at 1:50 pm

    You are not calling your printoscreen function. Try adding printtoscreen(); before the end of your main() function.

    EDIT:

    Also consider changing int printoscreen(){ to void printoscreen(){ and correspondigly return 0; to just return; in this function, as you are not returning anything meaningful, and are ignorig result value in main. So the enitre code would be:

    #include <iostream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <sstream>
    #include <cstdio>
    using namespace std;
    
    ifstream file("maze.txt");
    vector<char> vec(istreambuf_iterator<char>(file), (istreambuf_iterator<char>())); // Imports characters from file
    vector<char> path;                      // Declares path as the vector storing the characters from the file
    int x = 18;                             // Declaring x as 18 so I can use it with recursion below
    char entrance = vec.at(16);             // 'S', the entrance to the maze
    char firstsquare = vec.at(17);          // For the first walkable square next to the entrance
    vector<char> visited;                   // Squares that we've walked over already
    
    void printtoscreen();
    
    int main()
    {
        if (file) {
            path.push_back(entrance);               // Store 'S', the entrance character, into vector 'path'
            path.push_back(firstsquare);            // Store the character of the square to the right of the entrance
                                                    // into vector 'path'.
            while (isalpha(vec.at(x)))
            {
                path.push_back(vec.at(x));
                x++;
            }
        }
        printtoscreen();
    }
    
    void printtoscreen()
    {
        cout << "Path is: ";                    // Printing to screen the first part of our statement
    
            // This loop to print to the screen all the contents of the vector 'path'.
            for(vector<char>::const_iterator i = path.begin(); i != path.end(); ++i)  // 
            {
            std::cout << *i << ' ';
            }
    
            cout << endl;
            cin.get();                          // Keeps the black box that pops up, open, so we can see results.
            return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I draw something on the screen ? not the console window but
The thing is, I really don't want the console window to show up, but
I have a simple Console Project in Visual Studio that I want to run
I want to run a console application that will output a file. I user
I want to a create dialog box like window before displaying the console window.
I have console application in c. I want to convert into window application, kindly
I want to run a console application (eg app.exe) from a windows form load
I created a console application, but I want to turn it into a windows
Im playing around in C# and want my little console program to spell my
I want to make an console application of c which can run other applications

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.