help!!!

This is a discussion on help!!! within the C++ Programming forums, part of the General Programming Boards category; This program seems like it should work but it isn't it is probably something stupid that im doing wrong,but i ...

  1. #1
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Question help!!!

    This program seems like it should work but it isn't it is probably something stupid that im doing wrong,but i cant figure it out
    i dont really know how to use code tags so if u can not read this u can download the program

    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    using namespace std;

    int main(int argc, char* argv[])
    {ofstream fout;
    ifstream fin;float a,b,c;

    fout.open("A:/outfile.dat", ios:ut);

    for(int i=0;i<20;i++){

    a=0;
    b=0;
    c=1;
    cout<<"Enter three numbers: \n";
    cin>>a>>b>>c;
    fout<<a<<b<<c<<endl;
    }
    fout.close();

    fin.open("A:/outfile.dat",ios::in);
    for (int j=0;j<20;j++){
    fin>>a>>b>>c;
    cout<<a<<" "<<b<<"/"<<c<<endl;

    }
    fin.close();



    return 0;
    }
    Attached Files Attached Files

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Try outputting the numbers seperated by a space. You're reading and writing in text mode which means your ifstream object won't be able to tell when one number ends and another starts.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21