Thread: file streams

  1. #1
    Unregistered
    Guest

    Question file streams

    Is it possible to close just the name portion of an input stream and not the stream itself
    sample code
    int main()
    {

    ifstream baseline;
    ifstream input;
    ofstream output;

    baseline.open("sel000.xls",ios::in); //open baseline file
    output.open("output.dat",ios:ut); //open output file

    i = 0;
    for(int k = 1; k <=2;k++)
    {
    //do some stuff
    input.open(infile,ios::in); //open input file

    i = 0;
    while(input >> time >> first)
    {
    //do some stuff change and chang the name of infile
    }
    input.close();//instead of closing input is it possible to close just infile so that the loop will work
    }

    yes I know you can move ifstream input; into the loop but I do not want to make it a local varaible

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    18
    Use [ code ]
    tags please...
    Then I will be able to help you.
    HACKERS MANIFESTO (NOTE MOST WAS CUT OFF) (PEOPLE SAID IT WAS TOO LONG)
    This is our world now... the world of the electron and the switch, the beauty of the baud.
    · We make use of a service already existing withoutpaying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals.
    · We explore... and you call us criminals.
    · We seek after knowledge... and you call us criminals.
    · We exist without skin color, without nationality, without religious bias... and you call us criminals.
    · You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals.

    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

    I am a hacker, and this is my manifesto. You may stop this individual,but you can't stop us all... after all, we're all alike.
    +++The Mentor+++

  3. #3
    Unregistered
    Guest

    here is the entire source code

    I am not sure by what ou mean [code] tags I looked at the FAQ but not to much guidance there. So here it is. It is used to read in the columns of data in an excel file.

    #include <stdio.h>
    #include <iomanip>
    #include <iostream>
    #include <fstream>

    using namespace std;


    const int maxtime = 1200;
    const int maxrun = 4;

    int main()
    {

    ifstream baseline;
    ifstream input;
    ofstream output;

    char infile[20];
    char dat[] = ".xls";
    char buffer[100];

    float time;
    float selected;
    float first;

    float data[maxtime][maxrun] = {0,0};

    int i;
    int j;
    int tmp;
    int hun;
    int ten;
    int one;



    baseline.open("sel000.xls",ios::in); //open baseline file
    output.open("output.dat",ios:ut); //open output file

    i = 0;
    while(baseline >> time >> selected)
    {
    data[i][0] = time;
    data[i][1] = selected;
    i++;
    }

    for(int k = 1; k <=2;k++)
    {

    hun = k/100;
    ten = (k%100)/10;
    one = k%10;

    tmp = sprintf(buffer,"sel%d%d%d",hun,ten,one);

    strcpy(infile, buffer);
    strcat(infile,dat);

    input.open(infile,ios::in); //open input file

    i = 0;
    while(input >> time >> first)
    {
    data[i][k] = first;
    i++;
    }
    input.close();
    }

    for (i = 0; i < maxtime; i++)
    {
    for (j = 0; j < maxrun; j++)
    {
    output << setprecision(9) << setiosflags(ios::fixed | ios::showpoint) ;
    output << data[i][j] << '\t' ;
    }
    output << endl;
    }
    return 0;

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM