1HAWK1
@1HAWK1

Как исправить ошибку в коде С++?

Помогите исправить ошибку в коде.
Код ошибки в VS:
Ошибка C3861 gets: идентификатор не найден

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
    char fileName[30], ch;
    fstream fps, fpt;
    cout << "Enter the Name of File: ";
    gets(fileName);
    fps.open(fileName, fstream::in);
    if (!fps)
    {
        cout << "\nError Occurred, Opening the Source File (to Read)!";
        return 0;
    }
    fpt.open("tmp.txt", fstream::out);
    if (!fpt)
    {
        cout << "\nError Occurred, Opening/Creating the tmp File!";
        return 0;
    }
    while (fps >> noskipws >> ch)
    {
        ch = ch + 100;
        fpt << ch;
    }
    fps.close();
    fpt.close();
    fps.open(fileName, fstream::out);
    if (!fps)
    {
        cout << "\nError Occurred, Opening the Source File (to write)!";
        return 0;
    }
    fpt.open("tmp.txt", fstream::in);
    if (!fpt)
    {
        cout << "\nError Occurred, Opening the tmp File!";
        return 0;
    }
    while (fpt >> noskipws >> ch)
        fps << ch;
    fps.close();
    fpt.close();
    cout << "\nFile '" << fileName << "' Encrypted Successfully!";
    cout << endl;
    return 0;
}
  • Вопрос задан
  • 290 просмотров
Решения вопроса 1
Комментировать
Пригласить эксперта
Ответы на вопрос 1
0hquazEd
@0hquazEd
В стандартной библиотеке нет функции gets.

Вы можете сделать тоже самое, используя этот код

#include <iostream>
#include <fstream>
#include <string>

int main()
{
	std::string file_name;
	std::cout << "Enter file name: " << std::endl;
	std::getline(std::cin, file_name);

	std::ifstream ifstream(file_name);

	std::string data_to_encrypt;
	std::getline(ifstream, data_to_encrypt);

	ifstream.close();

	for (auto& ch : data_to_encrypt)
	{
		ch += 100;
	}

	std::ofstream ofstream(file_name, std::ios::trunc | std::ios::out);
	
	ofstream << data_to_encrypt;
	ofstream.close();

	return 0;
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы