Can anyone solve this: How to add two matrix from .txt file and store the result to another .txt file and print the result in c++

Can anyone solve this: How to add two matrix from .txt file and store the result to another .txt file and print the result in c++
0

#1

Can anyone solve this: How to add two matrix from .txt file and store the result to another .txt file and print the result in c++


#2

I don’t know everything for certain, but my first thought is to do this:

  1. Make file readers
  2. Get the matrices
  3. Use a For Loop to go through the matrices and add the numbers together. (Might need a double For loop).
  4. Make a file writer.
  5. Write to the file.
    I have no idea how to do the c++ thing though.

#3

@risobuj,
I won’t post a solution here, but I’ll give you enough to build one on your own:
To be able to handle files in C++, you must include the fstream library.
Then you can declare a file to be read from as ifstream myFile(NameOfYourFile).
If you want to declare a file to write to, you write ofstream myFile(NameOfYourFile)
You then need to check that the file was successfully opened using myFile.is_open().
At the end you need to close your file with myFIle.close().
Reading from a file can be done using the getline(myFile, line) command where line is a string variable.

I think that pretty much covers everything you need to know. If you need any more help, let us know.