Dev - C++ - Añadirle una linea la cual sea para escribir texto

 
Vista:
sin imagen de perfil
Val: 36
Ha disminuido su posición en 3 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Añadirle una linea la cual sea para escribir texto

Publicado por Mario Alberto (19 intervenciones) el 13/02/2020 04:25:49
AMIGOS NECESITO AYUDA EN ESTE PROGRAMA , TENGO QUE AÑADIRLE UNA LINEA A LA CUAL SEA PARA ESCRIBIR TEXTO. AYUDA POR FAVOR ES EN C++ URGENTE.... EL CATEDRATICO ME DIO ESTA PAGINA DE INTERNET ES www..cplusplus.com/doc7tutorial/files/ AHI VIENE COMO SE HACE PERO NO ENTIENDO AYUDA


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
 
//escriba en un archivo de texto reemplazando lo existente
bool escribe() {
	ofstream myfile("ejemplo.txt");
	if (myfile.is_open())
	{
 
		int a = 20;
		double b = 3.141592;
		myfile << "esta es una linea.\n";
		myfile << "esta es otra.\n";
		myfile << "el entero es " << a << endl;
		myfile << "el doble es " << b << endl;
		myfile << "ultima linea del archivo" << endl;
		myfile.close();
		return true;
	}
 
	else {
		cout << "no se pudo abrir el archivo." << endl;
		return false;
	}
 
 
	//lectura de un archivo de texto
	bool lectura() {
		string line;
		ifstream myfile("ejemplo.txt");
		if (myfile.is_open())
		{
			while (getline(myfile, line))
			{
				cout << line << endl;
			}
			myfile.close();
			return true;
		}
		else {
			cout << "no se puede abrir el archivo" << endl;
			return false;
		}
	}
	//checar el tamaño de un archivo
	streampos tamanho() {
		streampos begin, end;
		ifstream myfile("ejemplo.txt", ios::binary); //abrir como binario
		begin = myfile.tellg();     //checamos el inicio
		myfile.seekg(0, ios::end);  //buscamos el final
		end = myfile.tellg();       //checamo el final
		myfile.close();
		cout << "el tamanho es: " << 8end - begin) << " bytes.\n";
		return end - begin;
 
	}
int main()
{
	int opcion = 0;
	while (opcion != 9) {
		cout << "**************************" << endl;
		cout << "*                         " << endl;
		cout << "* 1) escribe un texto    *" << endl;
		cout << "* 2) lee un texto         *" << endl;
		cout << "* 3) checa el tamanho     *" << endl;
		cout << "* 9) termina              *" << endl;
		cout << "*                         *" << endl;
		cout << "*    elige una opcion     *" << endl;
		cout << "*                         *" << endl;
		cout << "***************************" << endl;
		cin >> opcion;
		if (opcion == 1)
			escribe();
		else if (opcion == 2)
			lectura();
		else if (opcion == 3)
			tamanho();
		cout << endl;
	}
	return 0;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder