S
S
Samoniel2020-10-08 10:43:15
C++ / C#
Samoniel, 2020-10-08 10:43:15

Translation of pascal code to c++?

please help, I don't understand what to write in c++ in place of read(f,c1) and reset (f), and is it necessary. I have been looking for an answer for several hours and learning topics, please help

var k, i, max: integer;
c1, c2: char;
f: text;
begin
    assign(f,'C:\24.txt');
    reset(f);
    c1 := '0';
    c2 := '0';
    k := 1;
    max := 1;
    while not Eof(f) do begin
        c2 := c1;
        read(f, c1);
        if (c1 <> c2) and ((c2 <> '0') or (c1 <> '0')) then begin
            k := k + 1;
        end
        else begin
            if k > max then 
                max := k;
            k := 1;
        end;
    end;
    if k > max then 
        max := k;
    writeln(max);
end.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Samoniel, 2020-10-09
@Samoniel

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
    char c1, c2;
    int i, k, max;

    ifstream file("S:\\some shit\\24_demo.txt");
    
    c1 = '0';
    c2 = '0';
    k = 1;
    max = 1;
    

    while(!file.eof())
    {
        c2 = c1;
        file >> c1;

        if (c1 != c2 & (c2 != '0' || c1 != '0'))
        {
            k = k + 1;
        }
        else
        {
            if (k > max)
            {
                max = k;
            }
            k = 1;
        }
    }
    if (k > max)
    {
        max = k;
    }
    cout << max;
    

    


    return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question