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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:15:45+00:00 2026-06-04T21:15:45+00:00

I am wondering is it okay to return a vector in main() ? For

  • 0

I am wondering is it okay to return a vector in main()? For example,

aSpecialVectorType main()
{
    aSpecialVectorType xxx(vector::zero);
    // do something here;
    return xxx;
}

Do I need to forward declare “class aSpecialVectorType;” before main()?

And btw, is it legal to use another name other than “main” in c++?

Thanks

Edit1:

If not, what is the best way that it can output a vector?

My friend ask me to give him a blackbox that can serve as “vector in and vector out”, he will use his matlab code to call my code. That’s why I am asking.
I know how to vector in, but not sure if there is an easy way to output a vector.

Thanks

Edit2:

I am surprised why C++ has such an standard, any explanation? 🙂

  • 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-04T21:15:47+00:00Added an answer on June 4, 2026 at 9:15 pm

    In C++, main needs to return an int:

    C++ standard, 3.6.1.2:

    An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined.

    .

    If not, what is the best way that it can output a vector?

    To output a vector, you need to copy it to a file or an output stream:

    ostream_iterator<int> out_it(cout, ", ");
    copy(myvector.begin(), myvector.end(), out_it);
    

    The code fragment above writes the content of vector<int> to the standard output.

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

Sidebar

Related Questions

I'm wondering whether it's considered okay to do something like this. if ( p_Pointer
Wondering if following will work for google in robots.txt Disallow: /*.action I need to
Wondering if I could get some advice and direction on this following requirement: Need
Wondering if I can speed up the search. I need to build a functionality
Okay I was wondering when should I sanitize my code, when I add store
Okay so, I'm wondering how to unbind an inline onclick event in jQuery. You'd
Okay, I am wondering having clear web.config file could be good but you know
I'm wondering if it's considered okay (particularly, in Django) to have a URL that's
Okay, so here is the basic background. This program connects to outlook/exchange and parses
Okay, I'm new to blackberry development and I was wondering if anyone could give

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.