@iama
1251 / 976 / 49
Регистрация: 30.07.2010
Сообщений: 5,297
|
29.08.2010, 23:00
|
|
В стиле Си
C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
size_t count;
char const *str = "привет\n";
fp = fopen("пример.txt", "wb");
if(fp == NULL) {
perror("ошибка открытия пример.txt");
return EXIT_FAILURE;
}
count = fwrite(str, 1, strlen(str), fp);
printf("Записано %lu байт. fclose(fp) %s.\n", (unsigned long)count, fclose(fp) == 0 ? "успешно" : "с ошибкой");
return 0;
} |
|
В стиле С++
C++ | 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
| #pragma hdrstop
#include <fstream>
#include <conio.h>
#include <string.h>
using namespace std;
#define nl '\n'
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
fstream str("c:\\test.txt",ios_base::in|ios_base::out|ios_base::trunc);
for(int i=0;i<5;i++)
{
char s[100];
cin>>s;
str<<s<<'\n';
};
str.seekp(0);
while(!str.eof())
{
char s[100];
str.getline(s,100,'\n');
cout<<s<<'\n';
};
getch();
str.close();
return 0;
} |
|
1
|