这是我到目前为止的代码.
我需要做的是从两个不同的文本文件,矩阵A和矩阵B中读取.
我可以这样做但是对于我读过的每个文本文件矩阵,它只能得到它
1 0 0
Run Code Online (Sandbox Code Playgroud)
(所以基本上是第一行)实际上是Matrix A的整个文本文件
1 0 0
2 0 0
3 0 0
Run Code Online (Sandbox Code Playgroud)
那么有谁知道我怎么做到这一点?
谢谢!
#include <iostream> //declaring variables
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
string code(string& line);
int main()
{
ofstream outf;
ifstream myfile;
string infile;
string line;
string outfile;
cout << "Please enter an input file (A.txt) for Matrix A or (B.txt) for Matrix B" << endl;
cin >> infile; //prompts user for input file
if (infile == "A.txt")
{ //read …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一个函数应用于向量,其中对于每个新行,相同的函数适用但变量更改.例如,如果我有一个带N行的向量:
A = [1.2; 1.5; 1.8; 2.3; 2.7; 2.8; 2.9];
Run Code Online (Sandbox Code Playgroud)
我想n*0.1从每一行中减去n = row number.因此1.5,在行2中将减去0.2 (2*0.1),2.8在行6中将减去0.6 (0.1*6),依此类推.
为了澄清,我想这对我的档案上写着一个函数,确定这是行n,我想减去行的数量n由n乘以0.1.我希望代码能够逐行读取文件,因此最终结果是向每行完成上述操作的向量.我想需要一个循环?
我确信解决方案很简单,但我不知道该怎么做.
我有以下几次
1.1
1.15
1.19
1.32
1.69
2.12
2.36
2.86
3.25
3.67
3.77
3.91
...
Run Code Online (Sandbox Code Playgroud)
我希望MALTAB读取时间并将数字存储到数组中,其中数组1将在1-2秒内存储.阵列2将是2-3秒,依此类推.
提前感谢您提供的任何帮助/建议