Quantcast

Maximum PC

It is currently Thu Sep 18, 2014 3:56 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: File input problem
PostPosted: Wed May 04, 2005 3:43 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
How would I read this data below from a file and output? Maybe read in a line at a time and output or something??? C++

Code:
The first list:
  147.90
   88.32
   88.32
   65.40
   32.30
   12.00
   10.00
    0.77
    0.05
    0.00
  -12.50
  -95.80
-1329.20

First list average is:  -76.34



The positive list:
  147.90
   88.32
   88.32
   65.40
   32.30
   12.00
   10.00
    0.77
    0.05
    0.00
Second list average is:  44.51


Top
  Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 4:03 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Sounds like a good approach.

Do you think that won't work for some reason?
Have you tried it on scratch paper?


Top
  Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 4:40 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
Code:
#include <fstream>
#include <iostream>
#include <string>
//...
std::string data;
std::ifstream file_in(<filename>);

//...
std::getline(file_in, data);

//now you have the line in data. use std::getline() again to get the next line


Top
  Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 5:36 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
Gadget wrote:
Sounds like a good approach.

Do you think that won't work for some reason?
Have you tried it on scratch paper?


I've never been taught file input or output so I struggle really badly with it.


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 10:22 am 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
I'm trying this and it isn't working...
Code:
ifile.open("output.txt",ios::in);
string data;
while(!ifile.eof())
{
   infile.getline(data);
   cout<<data<<endl;
}



Error

Code:
Assignment 5 source code.cpp
K:\Computer Science\Assignment 5\Assignment 5 source code.cpp(115) : error C2661: 'getline' : no overloaded function takes 1 parameters
K:\Computer Science\Assignment 5\Assignment 5 source code.cpp(116) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (o
r there is no acceptable conversion)


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 1:50 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
Bump - Oingy Boingy


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 2:08 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
got it, thanks


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group