- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想从文件中读取矩阵并在我的程序中使用它。但是当我输出结果时,它显示它没有正确读取。这是代码:
#define I 5
#define J 5
#define P 2
int i,j,k; //for loops
int main ()
{
ifstream inFile;
ofstream outFile;
double C[I][J];
inFile.open("C.txt", ios::in);
if (! inFile) {
cerr << "unable to open file C.txt for reading" << endl;
return 1;
}
for(i=0; i<I; i++)
for(j=0; j<J; j++)
inFile >> C[i][j];
outFile.open("results.txt");
outFile<< "C" <<endl;
for(i=0;i<I;i++)
{
for(j=0;j<J;j++)
outFile<< C[i][j];
outFile<< endl;
}
inFile.close();
outFile.close();
return 0;
}
C 是一个整数值矩阵 2 3 5... 但我得到的是
316-9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061 -9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061 -9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061 -9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061 -9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061-9.25596e+061
最佳答案
你应该在每个数字后输出一个空格,否则它们会粘在一起。
outFile<< C[i][j] << " ";
您还应该检查输入的有效性。此处不显示(您已经知道如何检查 if (!inFile)
)。
关于c++ - 如何从 .txt 文件读取表格到 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9447787/
问题是这个。我有: f :: MonadIO m => ReaderT FooBar m Answer; f = (liftIO getArgs) >>= ... 我需要使用修改后的参数运行它。但是,
在这里,我试图对C++中的xtensor库进行非常基本的操作。我有xarray a,并且有了index related function xt::where,我想获取条件为True的索引数组(请注意,
我想以与 numpy 相同的方式获得重复数组但是 xt::repeat返回表达式。当我尝试将此表达式转换为数组时,出现编译错误。 xt::array a = {{1, 2}, {3, 4}}; aut
最近,Perl 世界中出现了新的伟大事物。长期以来在 库包有文件夹t包含测试。现在有一个 更多文件夹xt包含作者测试。 xt不需要测试 库安装的过程,但它有助于库作者 确保代码很棒。 有一个 Spri
This link cuBLAS-XT 例程提供核外操作 - 操作数数据的大小仅受系统内存大小的限制,而不受 GPU 板载内存大小的限制。这意味着只要输入数据可以存储在 CPU 内存上并且输出大小大于
有谁知道Stratego/XT编程语言?到底有什么好处呢?有什么好的和/或不好的经历吗?任何真实的现场运行示例? 非常感谢。 最佳答案 Stratego/XT 是一种基于术语重写和可编程重写策略的程序
我有一个使用 VueJS 处理的 map ,但我在事件connectorClick 方面遇到问题。在下面的示例中,当单击连接线时,警报不起作用。 Vue.use(VueFusionCharts, Fu
我刚开始使用 xtensor,我已经陷入了一个基本问题。 我正在使用类似 xt::sum(xt::where(egoLaneLeftCount, 1, 0)) 的方法对列求和并获得单个整数值。我想将这
我是 xtensor 的新手。我想知道如何使用 xt::where 的输出。在 python 中,例如假设 imap 是一个 nd 数组, np.where(imap>=4) 返回两个带索引的数组,可
每次从没有文档的 jQuery Carousel 插件调用 switchSlide() 方法时,我都会触发一个自定义事件 switchSlideEvent 。 我正在使用 Lazy Load XT (
知道如何强制加载特定 div 的Lazy Load XT jQuery plugin ? 我的意思是 data-src="" 图像将在页面加载后自动加载而无需页面滚动或视口(viewport)。 此插
我正在尝试在 xarray 中查找某些数组值的索引值。我有一个名为 lattice 的 xarray,其中包含数字 1 到 n,我想要的是类似 auto x2 = xt::where(lattice
我的蓝牙耳机 (Parrot B350-XT) 有 4 个按钮: 调高音量 调低音量 电源按钮 “鹦鹉”按钮 我正在创建一个在三星 SM-T230NU 上运行的 Android 应用程序 (OS 4.
概述 我正在尝试让 XQuartz 在 OSX 上工作,这样我就可以通过 Docker 进行 X11 转发。我关注 the instructions here .我相信我的问题可能只由第一部分回答,但
不久前,Perl 世界中出现了新事物。事情是创造xt模块源代码中的目录并在那里放置应该 只能由作者运行。 xt 的想法测试是它们没有运行时 该模块是从 CPAN 安装的。 我在想如果安装过程不需要测试
我确实尝试过了解 Stratego/XT 的第一步。我在谷歌上搜索了很多,我发现的所有网络资源在开始时似乎都取得了足够大的飞跃,以至于我无法建立联系。让我解释一下。 我是这样理解抽象语法树的: Min
很久以前,我为 xt:Commerce 构建了一个导入器,在 v4.1 之前运行良好。数据来自与以前相同的 PIM 系统。 但是现在,v4.2.0 已经出来了,他们为类别添加了一个嵌套集。无论如何没关
我是 Xcode 的新手,我正在学习它并尝试一些东西......现在我尝试通过 FusionCharts XT 在 iOS 上绘制图表。我将 webView 添加到我的屏幕并从 FusionChart
Android 接口(interface)上的网络接口(interface)在 /sys/class/net/ 中的文件系统中作为目录列出。 对于大多数 Android 设备,gprs 流量的网络接口
我有一个用 Xt(X Tools Intrinsic 库)编写的名为 XClient 的类,用于设置多套接字连接。这个 XClient 类用于 OSF/Motif GUI 以扩展 XClient(因此
我是一名优秀的程序员,十分优秀!