English 中文(简体)
它没有从档案中输出数据。 我不理解问题是什么。
原标题:It does not output data from the file. I do not understand what the problem is
  • 时间:2023-12-12 22:47:03
  •  标签:
  • c++

It does not output data from the file, but only characters. Before that, everything worked, but now I can t figure out what the problem is.

C6031 回归价值:“scanf”

“image”/

void func_list()
{
    int row;
    system("cls");
    Title();
    FILE* ek;
    ek = fopen("Record2.dat", "r");
    cout << "

			!!!!!!!!!!!!!! List Patients Record !!!!!!!!!!!!!
";
    gotoxy(1, 15);
    cout << "Имя";
    gotoxy(20, 15);
    cout << "Пол";
    gotoxy(32, 15);
    cout << "Возрост";
    gotoxy(37, 15);
    cout << "Адрес";
    gotoxy(49, 15);
    cout << "Контакты";
    gotoxy(64, 15);
    cout << "Почта";
    gotoxy(88, 15);
    cout << "Диагноз";
    gotoxy(98, 15);
    cout << "Принимающий доктор
";
    cout << "=================================================================================================================";
    row = 17;
    while (fscanf(ek, "%s %s %c %i %s %s %s %s %s
", p.First_Name, p.Last_Name,
        &p.Gender, &p.age, p.Address, p.Contact_no, p.Email, p.Problem, p.Doctor) != EOF)
    {
        gotoxy(1, row);
        cout << "%s %s", p.First_Name, p.Last_Name;
        gotoxy(20, row);
        cout << "%c", p.Gender;
        gotoxy(32, row);
        cout << "%i", p.age;
        gotoxy(37, row);
        cout << "%s", p.Address;
        gotoxy(49, row);
        cout << "%s", p.Contact_no;
        gotoxy(64, row);
        cout << "%s", p.Email;
        gotoxy(88, row);
        cout << "%s", p.Problem;
        gotoxy(98, row);
        cout << "%s", p.Doctor;
        row++;
    }
    fclose(ek);
    getch();
    MainMenu();
}

看来所有东西都与《刑法》相符。 我无法理解为什么是产出,而不是档案中的必要数据。

“image”/

问题回答

<代码>operator<<不支持像你正在尝试使用的那样采用印刷式光谱仪。 因此,你正在印刷具体内容,然后援引comma(,营运人)阅读和抛弃你想要印刷的价值观。

如果你想要使用印刷式光谱仪,那么你需要使用实际的<代码>(std:)印本/编码功能,例如:

#include <cstdio>

...
printf("%s %s", p.First_Name, p.Last_Name);
...
printf("%c", p.Gender);
...
printf("%i", p.age);
...

或者,你可以使用更安全的std:format( in C++20 and subsequently (or >{fmt}/code><><>>><>>>>/code><>><>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><>>>>>>

#include <iostream>
#include <format>

...
cout << format("{} {}", p.First_Name, p.Last_Name);
...
cout << format("{}", p.Gender);
...
cout << format("{}", p.age);
...

否则,仅使用<代码>operator<<本身,例如:

...
cout << p.First_Name << " " << p.Last_Name;
...
cout << p.Gender;
...
cout << p.age;
...

As for the rest of your code, you should not be using gotoxy() at all, that is ancient! Instead, use standard I/O stream manipulators with operator<<, such as std::setw() and std::setfill(), eg:

#include <iostream>
#include <iomanip>
#include <cstdio>
...

Title();
cout << "

			!!!!!!!!!!!!!! List Patients Record !!!!!!!!!!!!!






";
cout << setfill(   ) << left;
cout << setw(20) << " Имя";
cout << setw(12) << "Пол";
cout << setw(5)  << "Возрост";
cout << setw(12) << "Адрес"
cout << setw(15) << "Контакты"
cout << setw(24) << "Почта"
cout << setw(10) << "Диагноз"
cout << setw(20) << "Принимающий доктор";
cout "
=================================================================================================================
";
while (...)
{
    char name[21];
    sprintf(name, sizeof(name), " %s %s", p.First_Name, p.Last_Name);

    cout << setw(20) << name;
    cout << setw(12) << p.Gender;
    cout << setw(5)  << p.age;
    cout << setw(12) << p.Address;
    cout << setw(15) << p.Contact_no;
    cout << setw(24) << p.Email;
    cout << setw(10) << p.Problem;
    cout << setw(20) << p.Doctor;
    cout <<  
 ;
}
...




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签