Last active
May 12, 2018 09:48
-
-
Save Leva-kleva/ae7c8e2090af7f880799f61c7add3cb4 to your computer and use it in GitHub Desktop.
for Marina
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <io.h> | |
using namespace std; | |
int main() | |
{ | |
int flg = 0; //флаг. если =1 то файл с введенным названием был найден, иначе не найден и цикл повторяется | |
while (flg == 0) | |
{ | |
try //обработка исключения | |
{ | |
ofstream file; //поток для файла | |
string namefile; //имя файла считываем с клавиатуры | |
getline(cin, namefile); | |
if (access(namefile.c_str(), 0) == -1) // проверка на то есть ли файл. если возвращает -1 то пустой иначе не пустой | |
{ | |
throw 321; //генерируем число. С этого момента все что ниже пропускается. Работает блок catch | |
} | |
file.open(namefile.c_str()); //открываем файл. c_str() преобразует string в char* | |
string str; | |
while (cin >> str) //цикл для чтения всей информации введеной с клавиатуры. Причем если введеная строка- stop то мы прекращаем запись. хокку готова | |
{ | |
if (str == "stop") | |
{ | |
break; | |
} | |
file << str << endl; | |
} | |
file.close(); | |
flg = 1; | |
} | |
catch(int n) | |
{ | |
cout << " file not found. Go new file. Sorry za my bad english" << endl; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template <typename my_type> //говорим, что это шаблон | |
void print_array (my_type* array, int size) //функция вывода массива на экран. принимает массив типа my_type и его размер | |
{ | |
for (int i = 0; i < size; i++) | |
{ | |
cout << array[i]; | |
} | |
cout << endl; | |
} | |
int main() | |
{ | |
//пример работы | |
int arr1[5] = {0, 1, 3, 1, 4}; //массив целых чисел | |
char arr2[5] = {"keka"}; //массив букв | |
//вывод на экран | |
print_array(arr1, 5); | |
print_array(arr2, 5); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment