Thread: how can i writ in file like test.txt??!

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    11

    how can i writ in file like test.txt??!

    I have 2d array (float) having some values , i want my program create a file if it not exist , and i want to write the values of 2d array (float) in this file , please can any one help me , I am beginner in programming .

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    check this link out:
    Input/Output with files

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main () {
      ofstream myfile;
      myfile.open ("example.txt");
      myfile << "Writing this to a file.\n";
      myfile.close();
      return 0;
    }
    This code creates a file called example.txt and inserts a sentence into it in the same way we are used to do with cout, but using the file stream myfile instead

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    Quote Originally Posted by ahmed eltaher View Post
    I have 2d array (float) having some values , i want my program create a file if it not exist , and i want to write the values of 2d array (float) in this file , please can any one help me , I am beginner in programming .
    1- you need 2 loops to check the 2 dimention array cells
    2- if the value is not 0 then write it in the file using the instruction in the previous post.


    good luck

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    You're doing matrix multiplication with MPI, and yet you can't figure out how to write to a text file? Dude, your priorities are out of whack here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2010, 12:05 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM