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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:48:53+00:00 2026-05-26T18:48:53+00:00

If I use std::cin, std::cout and std::string, is there any possibility that someone will

  • 0

If I use std::cin, std::cout and std::string, is there any possibility that someone will exploit the buffer overflow?

I ask this because I still see a lot of people that still use null-terminated strings instead of standard containers in C++.

  • 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-05-26T18:48:54+00:00Added an answer on May 26, 2026 at 6:48 pm

    It depends. Of course, when you use C-style code/API’s, there is no difference.

    But using STL or C++ idioms doesn’t guarantee that you’re safe.

    C++ gives you the choice, always. Contrast these two near-identical twins:

    int n;
    std::cin >> n;
    std::string s(n, '*'); // create a data store of given size
    
    std::vector<char> v(1000);
    std::copy(s.begin(), s.end(), v.begin()); // NOT safe if n > 1000
    

    safe variant:

    int n;
    std::cin >> n;
    if (n > MAX_LIMIT) 
        throw std::runtime_error("input too large");
    std::string s(std::min(0, n), '*'); // note input sanitation
    
    std::vector<char> v;
    v.reserve(1000);
    std::copy(s.begin(), s.end(), std::back_inserter(v)); // safe
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When should I use std::string and when should I use char* to manage arrays
I'm trying to use std::string instead of char* whenever possible, but I worry I
In attempting to use std::select1st from <functional> in a VS2008 project I found that
In an Xcode project, if I use std::cout to write to the console the
I'm writing a small/beta testing program that will be put to use in my
I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function
Why is it wrong to use std::auto_ptr<> with standard containers?
I know how to swap two variables in C++, ie you use std::swap(a,b) .
I am writing an embedded app. In some places, I use std::ostringstream a lot,
Assume I have a class foo, and wish to use a std::map to store

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.