高分求Java程序翻译成C++

来源:百度知道 编辑:UC知道 时间:2024/05/30 17:17:49
要求:从两个TXT文件中各读取一个超级大的矩阵,将读取出的两矩阵相乘,将所得的第三个矩阵写到第三个TXT文件中,读取的矩阵和输出的矩阵中,每行的两个相邻数用逗号隔开,计算运算时间,并将时间写入第三个文件中。

另附已经写好的JAVA源码如下:

import java.util.*;
import java.io.*;

public class Matrix {
public static void main(String[] args) {

Date date = new Date();
long previousTime = date.getTime();
long lastTime = 0;

//设置1个参数,如果等于1,则计算并把结果写入文件,且计算时间,如果等于2,计算并计算时间,不写文件,但计算结果,在 屏幕输出 如果等于3,only计算,不在屏幕输出结果,只显示计算时间~
int choose = 0;

choose = Integer.parseInt(args[0]);

//将结果输出到文件中
File f = new File("f://1.txt");
String strEncode = "UTF-8";

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), strEncode));

StringBuilder sb = new StringBuilder();

int Cut = 0;

int[][] b = ReadFile.read("F://3.txt");
int[][] c = ReadFile.r

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>

using namespace std;

void StringSplit(string str, string delim, vector<string> results)
{
int cutAt;
while( (cutAt = str.find_first_of(delim)) != str.npos )
{
if(cutAt > 0)
{
results.push_back(str.substr(0,cutAt));
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
results.push_back(str);
}
}

class ReadFile {
public:
static vector<vector<int>> read(const char* filename) {
int x = 0;
int y = 0;

vector<string> m;

ifstream f(filename);

string str;

vector<string> s;

char* buffer = new char[1024];
while(f.getline(buffer,1024)) {<