reading file

0 sumeet prasad · August 8, 2015
what is the piece of code that reads the data from the file located anywhere in the memory

Post a Reply

Replies

Oldest  Newest  Rating
0 Milan Obrenovic · August 8, 2015
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    // READING FROM THE FILE
    // 1st argument - your file name
    // 2nd argument - ALWAYS needs to be "r", which is used for input
    // 3nd argument - ALWAYS needs to be "stdin", which stands for standard input
    freopen("dokument.txt", "r", stdin);

    // WRITING TO FILE
    // 1st argument - output file name
    // 2nd argument - ALWAYS needs to be "w", which is used for output
    // 3rd argument - ALWAYS needs to be "stdout", which stands for standard output
    freopen("dokument1.txt", "w", stdout);

    int a, b, d;
    char input[1000];

    scanf("%d" "%d" "%s" "%d", &a, &b, &input, &d);

    int res = a + b + d;
    int length = sizeof(input) / sizeof(char);

    printf("%d\n", res);
    printf("%s " "%s\n", input, "Any type of string");
    printf("%d\n", length);

    // Converts character array into a string variable
    string newString(unos);

    cout << newString << endl;
    cout << newString.length() << endl;

    return 0;
}
  • 1

C++

107,192 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator