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

The Archive Base Latest Questions

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

Given such a code segment: #include <iostream> #include <iterator> #include <fstream> #include <string> using

  • 0

Given such a code segment:

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
using namespace std;
int main(){
    ifstream file("1.txt");
    string str((istream_iterator<char>(file)),istream_iterator<char>());
    file.close();
    cout<<str<<endl;
}

The code constructs a string from a file using istream_iterator.

Notice that the first parameter of string constructor is enclosed with a pair of parentheses. If I omit the parentheses, there will be an error. In VC++ 2008, a link error will come about. In G++, the code has a wrong output.

I feel very strange about the parentheses. What’s the difference and why?

  • 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-01T13:56:08+00:00Added an answer on June 1, 2026 at 1:56 pm

    Without the “extra” parentheses, you get C++’s “most vexing parse” — instead of defining an object named str with the two istream_iterators to specify its initializers, it’s parsed as a declaration of a function named str that returns a string, and the “stuff” in parentheses specifies the types of parameters it takes.

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

Sidebar

Related Questions

In the code given below, I am trying to modify it in such a
Given a string such as: a:2:{i:0;s:1:1;i:1;s:1:2;} I want to find every integer within quotes
Given a string such as: new/path - path/path/03 - filename.ext, how can I use
Given a piece of code such as: {$globalScript->qtip(active_page::getCurrentPageName()=='factsheet','../')} What's the difference in usage in
I have a code segment which is as simple as : for( int i
So I need some way of turning given Protocol://URLorIP:Port string into string ip int
i have been given a project where i will need to write code such
Given a tuple of type (Int, a) such as (n,c) , I wish to
Another stupid question here regarding a SQL scenario. Given data such as: FieldKey DocumentKey
Given a class such as: class Person { private: char *name; public: Person() {

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.