如何在列中追加数据
How do I append data in columns?
下面的代码将 y[i] 的值附加到与 x[i] 相同的列中,y[0] 从 x[10] 下面开始。我想将 y[i] 的值附加到 x[i] 值的第一列旁边的第二列中。你能帮我怎么做吗?
#include <fstream>
using namespace std;
int main() {
ofstream outfile;
double x[10], y[10];
for(int i=0; i<10; i++){
x[i] = i+10;
}
for(int i=0; i<10; i++){
y[i] = i-10;
}
outfile.open("result.txt", ios_base::app);
outfile << "loop: " << 1 << endl;
for(int i=0; i<10; i++){
outfile << x[i] << "n";
}
outfile << "loop: " << 2 << endl;
for(int i=0; i<10; i++){
outfile << y[i] << "n";
}
outfile.close();
return 0;
}
更改
outfile << "loop: " << 1 << endl;
for(int i=0; i<10; i++){
outfile << x[i] << "n";
}
自-
outfile << "loop: 1 t loop: 2" << endl;
for(int i=0; i<10; i++){
outfile << x[i] << " t "<<y[i]<<"n";
}
无需
outfile << "loop: " << 2 << endl;
for(int i=0; i<10; i++){
outfile << y[i] << "n";}
你想这样做吗?
#include <fstream>
using namespace std;
int main() {
ofstream outfile;
double x[10], y[10];
for(int i=0; i<10; i++){
x[i] = i+10;
y[i] = i-10;
}
outfile.open("result.txt", ios_base::app);
outfile << "loop: " << 1 << endl;
for(int i=0; i<10; i++){
outfile << x[i] << ' ' << y[i] << "n";
}
outfile.close();
return 0;
}
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- 将数据追加到C++中的数组
- 无法在链表 C++ 中追加数据
- C++ - 将文本追加到仅具有 NTFS"追加数据"权限的文件
- 如何在列中追加数据
- Rcpp:通过引用将行追加到数据帧
- 我的程序在尝试将数据集追加到类对象时遇到"Process returned -1073741819 (0xC0000005)"
- 访问 vtkActor 构造对象并追加新数据
- boost::udp socket.recieve_from() 将数据追加到缓冲区的末尾
- 哪个数据结构在追加Duplicate时提供了Replace操作
- 应用程序在向字符串追加数据时崩溃
- 如何将数据追加到存在数据的文件中
- QAbstractTableModel::insertRows正在将新数据追加到内部QList
- 无法在c++中使用追加模式在文件中插入数据