codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  I need help pleasee! My project is about using I/o Stream  ozz_blade at 19:31 on Thursday, July 17, 2008
 

Task of Program: I want to create this program that runs an input file (/forum/test.txt) that contains a matrix with dimensions (11 x11) meaning that there are 11 rows x 11 columns in the file called "/forum/test.txt". I want to read the exact dimension into an outfile (ofstream). However, After program is run, the final output is a huge line with all the data combined in the first line (0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 16 16 16 16 16 16 0 0 0 0 0 0 0....). I am supposed to get the same table that I have in the input file (11 rows x 11 columns), but not a line. I have the right program because it runs perfectly in the output screen, but not when I want to create an outfile ("/forum/outdata.txt")What can I Do??

Example of the inputfile: ("/forum/test.txt") that I want to run into the new file:
0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 0 0
0 0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0

Example of the outputfile ("/forum/outdata.txt") after program runs : 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 .......0 0 0 0 0


/ Headers
#include <iostream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include <cstddef>
#include <cstdlib>

using namespace std;


// Define variables
typedef float value_type;

int main ()
{

ifstream infile;
infile.open("/forum/test.txt");
ofstream outfile;
outfile.open("/forum/outdata.txt");

value_type data[11*11];

copy(istream_iterator<value_type>(infile),istream_iterator<value_type>(),data);

// Initialize Program
int n=0,m=0;
for (n=0; n < 11; n++)
{
for (m=0; m < 11; m++)
{
outfile << data[(n*11+m)]<< endl;
}
std::clog << std::endl;
}
infile.close();
outfile.close();
return 0;
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Web Hosting
•  Re: refresh parent after closing pop up window
•  [Help] Javascript Quiz
•  Page scrolls to top when hiding or showing a div
•  Site disconnects unexpectedly
•  Re: dynamic crystal report generation
•  px to cm or reverse converting
•  Re: Help Running VB script in Windows 2003
•  ONUNLOAD


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008