[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Input fil-format?



On Friday 17 January 2003 18:08, you wrote:
> sslug@sslug (Hans Henrik Hansen) writes:
> > Jeg har et par idéer til at løse opgaven, men jeg er kommet lidt i tvivl
> > om, hvorledes jeg skal 'strukturere' input filen - dvs. angive, _hvor_ ét
> > tal slutter (og næste begynder)?
>
> Hvad med bare at putte et tal på hver linje?

Sikkert OK - men i mellemtiden har jeg konstateret, at hvis jeg danner 
"num"-filen således:
tal1 tal2.....tali.......	(altså blot med alm. mellemrum mellem elementerne), 
så kører dette lille program:

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
 
int main() {
  vector<float> talraekke;
  int i;
  ifstream in("num");
  float tal; 
  while (in >> tal) 
     talraekke.push_back(tal); 
  for (i = 0; i < talraekke.size(); i++) 
     cout << talraekke[i] << " "; 
  endl; 
}


tilsyneladende udmærket - når jeg lige ser bort fra, at jeg vist strengt 
taget skulle bruge en 'for'-løkke ifm. indlæsningen (men det kan jeg ikke få 
til at virke!)

mvh
Hans


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *