Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // read_vectors_zuhra.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <fstream>
- #include <iostream>
- #include <vector>
- using namespace std;
- bool check_of_reading_file(FILE *file, const char* filename_p) {
- if((file=fopen(filename_p,"r")) == NULL) {
- printf("Ошибка при открытии файла.\n");
- return false;
- }
- return true;
- }
- bool check_of_writing_file(FILE *file, const char* filename_p) {
- if((file=fopen(filename_p,"w")) == NULL) {
- printf("Ошибка при открытии файла.\n");
- return false;
- }
- return true;
- }
- vector<vector<float>> read_data(const char* filename, int rows, int columns) {
- vector<vector<float>> data;
- data.resize(rows);
- for (int i = 0; i < rows; i++)
- data[i].resize(columns);
- FILE *file = NULL;
- if (check_of_reading_file(file, filename)) {
- file = fopen(filename, "r");
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < columns; j++) {
- fscanf(file, "%f", &data[i][j]);
- }
- }
- }
- return data;
- }
- void print_data(const char* filename, vector<vector<float>> vec) {
- FILE *file = NULL;
- if (check_of_writing_file(file, filename)) {
- file = fopen(filename, "w");
- for (int i = 0; i < vec.size(); i++) {
- for (int j = 0; j < vec[i].size(); j++) {
- fprintf(file, "%f ", vec[i][j]);
- }
- fprintf(file, "\n");
- }
- }
- }
- int main() {
- vector<vector<float>> good = read_data("good.txt", 11, 11);
- print_data("vyvod.txt", good);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement