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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:28:31+00:00 2026-05-22T11:28:31+00:00

Let me preface this question by saying I am not a very experienced programmer.

  • 0

Let me preface this question by saying I am not a very experienced programmer.

For competitions like google code jam, I write code like this:

#include <fstream>

using namespace std;

int main() {
    ifstream fin("file.in");
    ofstream oin("file.out");
    //Etc. I'll now write out my solution.
    //...
}

However, I noticed that many other code sources by other participants don’t use fstream at all and use iostream instead. Then they’ll use cout and cin as if they were reading and writing from the console.

How are they doing this? Can I do the same thing if I am using g++ and ubuntu?

EDIT: Since it was requested that I post an example of what I mean, here is code from participant ryuuga who solved large Bot Trust, Problem A from the recent ’11 qualification round.

He uses cin and cout but I don’t know how he is doing file i/o.

#include <iostream>
using namespace std;
#include <cstdio>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
typedef pair<int,int> pii;
#include <vector>
typedef vector<int> vi;
#include <queue>
#include <stack>
#define For(i,a,b) for(int i=(a);i<(b);++i)

#define ForI(i,a,b) for(int i=(a);i<=(b);++i)
#define ForAll(it,set) for(typeof(set.begin()) it = set.begin(); it!=set.end(); ++it)

typedef stack<int> si;
typedef queue<int> qi;

int main(){
    int t;
    cin>>t;
    ForI(tt,1,t){
        int n;cin>>n;
        int pos[2]={1,1}, time[2] = {0,0};
        int curTime = 0;
        For(i,0,n){
            char type; int button;
            cin>>type>>button;
            type = (type=='B'?1:0);
            int nextTime = 1+max(curTime, time[type] + abs(button - pos[type]));
            pos[type] = button;
            time[type] = nextTime;
            curTime = nextTime;
        }
        cout<<"Case #"<<tt<<": "<<curTime<<endl;
    }

    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-05-22T11:28:32+00:00Added an answer on May 22, 2026 at 11:28 am

    Imagine when you are using the shell in ubuntu. Almost everything is read by the console, cin and written to the console, cout. For instance

    cat "file.txt" | grep "Hello"
    

    cat would get the “file.txt” from the arguments given to main, i.e.

    main(int argc, char ** argv){
        // for the both cat and grep examples argc is 2
        // argv[1] contains "file.txt" for cat. 
        // open an ifstream and ouput it to cout. There's cat for you.
    }
    

    To find out what argv[0] contains, try it out!
    grep would read the same argument then read everything from cin, copy the input that matches argv[1] to cout

    EDIT: He is running his program with

    cat "downloaded-input-file.txt" | theprogram > output.txt
    

    Then submits the program. Or he might be using the < downloaded-input-file syntax. I’m keeping the initial explanation as it might be useful for the understanding of the process.

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

Sidebar

Related Questions

Let me preface this question by saying I've exhausted Google, or at least what
Let me preface this question by saying I use TextMate on Mac OSX for
So let me preface this by saying that I'm not an SQL wizard by
Let me preface this by saying this is not an actual situation of mine
Let me preface this question by stating that I'm not a C# developer. I'm
Ok guys, let me preface my question with this, This is not a technical
Let me preface the question by stating that I'm not a programmer and am
Let me preface this by saying that my code seems to work for all
First let me preface this question by saying that I'm fairly new to Javascript.
First off, let me preface this question by saying that my professor is firmly

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.