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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:44:54+00:00 2026-06-05T00:44:54+00:00

// file.in 12 13 // main.cpp fstream f(file.in, ios::in); int n; char c; f

  • 0
// file.in
12
13

// main.cpp
fstream f("file.in", ios::in);
int n;
char c;
f >> n;
f.get(&c);

After extracting the number 12, what is the next character? Is it newline or ‘1’? If I call getline instread of get, do I get an empty line or ’13’?

  • 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-05T00:44:57+00:00Added an answer on June 5, 2026 at 12:44 am

    It leaves the delimiter in the input buffer, so the next character you read will be a new-line. Note, however, that most extractors will skip white space (which includes new-line) before anything they extract, so unless you do call something like getline this won’t usually be visible.

    Edit: to test on something like ideone, consider using a stringstream:

    #include <sstream>
    #include <iostream>
    
    int main(){ 
        std::istringstream f("12\n13");
        int n;
        char c;
        f >> n;
        f.get(c); // get takes a reference, not a pointer. Don't take the address.
    
        std::cout << "'" << c << "'";
        return 0;
    }
    

    I wouldn’t expect to see a difference between a stringstream and an fstream in something like this.

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

Sidebar

Related Questions

I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
In my main file I have an array of character strings, char names[320][30], and
Using the following code to write to a file int main(int argc, char *
Compiling the following: // file main.cpp #include <string> #include <boost/lexical_cast.hpp> int main() { boost::lexical_cast<std::string>(
Say you've got the following simple main.cpp file: #include <cstdlib> #include <iostream> #include <fstream>
// diskbin.cpp : main project file. #include stdafx.h #include <windows.h> #include <iostream> #include <fstream>
#include <iostream> #include <fstream> #include <string> using namespace std; int main (int argc, char*
fstream file; Patient Obj(XXX,'M',XXX); file.open(Patients.dat,ios::in|ios::out|ios::app); file.seekg(ios::end); file.write((char*)&Obj,sizeof(Obj)); file.seekg(ios::beg); Patient x; file.read((char*)&x,sizeof(x)); x.printallInfo(); file.close(); I'm
Can't understand what is a problem here: I have got main.cpp file where I
In code: //file main.cpp LINT a = 12; LINT b = 3; a =

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.