在html中引入c++
introduce c++ into html
所以我需要创建一个学生和他在课堂上的分数的数据库。我通过使用大量的对象数组来实现,但我需要像表一样将其写入html文件中,并创建了特殊的函数save。
#include <iostream>
#include "windows.h"
#include <fstream>
#include "TkachenkoLab.h"
using namespace std;
void save(Student KI[]);
ofstream file_out("C:\Users\ТКаченко\Desktop\МП ЛАБ №7\LAB7\page.html");
int main()
{
SetConsoleCP(::GetACP());
SetConsoleOutputCP(::GetACP());
short n;
cout << "Ââåä³òü ê³ëüê³ñòü ñòóäåíò³â ãðóïè: ";
cin >> n;
cin.clear(); cin.sync();
cout << "n —-— ÑÒÂÎÐÅÍÍß ÃÐÓÏÈ Ê² —---n";
Student KI[n];
cout << "n —-— ÑÏÈÑÎÊ ÃÐÓÏÈ Ê² —---n";
short i;
for (i = 0; i < Student::cnt(); i++ )
cout << i+1 << ". " << KI[i].name << endl;
cout << "n —-— reading student —-— n";
for (i = 0; i < Student::cnt(); i++ )
KI[i].in_res();
save(KI);
if (file_out.is_open())
file_out.close();
return 0;
}
void save(Student KI[])
{
file_out.open("C:\Users\ТКаченко\Desktop\МП ЛАБ №7\LAB7\page.html",ios::trunc);
file_out << "<html>" << endl;
file_out << "<head>" << endl;
file_out << "</head>" << endl;
file_out << "<body>" << endl;
file_out << "<table class="simple-little-table">" << endl;
file_out << "<tr>" << endl;
file_out << "<td>студент</td>" << endl;
file_out << "<td>мп</td>" << endl;
file_out << "<td>кс</td>" << endl;
file_out << "<td>физра</td>" << endl;
file_out << "<td>средний бал</td>" << endl;
file_out << "</tr>" << endl;
for (short i = 0; i < Student::cnt(); i++ )
{
file_out << "<td>студент</td>" << endl;
file_out << "<td>"<<KI[i].name<<"</td>" << endl;
file_out << "<td>"<<KI[i].MP<<"</td>" << endl;
file_out << "<td>"<<KI[i].KC<<"</td>" << endl;
file_out << "<td>"<<KI[i].fiz_ra<<"</td>" << endl;
file_out << "</tr>" << endl;
}
file_out << "</table>" << endl;
file_out << "</body>" << endl;
file_out << "</html>" << endl;
file_out.close();
}
my class in library
#include <string>
using namespace std;
class Student
{
public:
Student();
static short cnt() { return cnt_stud; };
void in_res();
void out_res();
string name;
~Student() {};
short MP, KC, fiz_ra;
static short cnt_stud;
short s_bal () { return (short)(MP+KC+fiz_ra)/3; };
};
void Student::out_res()
{
}
Student::Student()
{
cout << "ПІБ студента: ";
getline(cin, name);
MP = 0;
KC = 0;
fiz_ra = 0;
cnt_stud++;
};
short Student::cnt_stud = 0;
void Student::in_res()
{
cout << name << ": ";
cin >> MP; cin >> KC; cin >> fiz_ra;
}
它甚至没有创建一个文件。我做错了什么?
首先在路径名中使用非ascii字符。我从来没有试过这样做,所以我不能帮你但也许你可以试试这里的答案打开文件与非ASCII字符
你写文件的方式不对。我假设您试图将所有学生写入同一个文件,但不要使您的文件成为全局变量,而是将其传递给这样的函数。
void save( std::ofstream &file, Student KI[] );
检查main中的内容,比如
int main() {
std::ofstream file( "PathOfFile" );
if ( file.is_open() ) {
// Do what you want to do with your file
save( file, student );
file.close();
}
else {
std::cout << "Failed to open file" << std::endl;
}
return 0;
}
这对我们来说更容易阅读,对你来说更容易使用
相关文章:
- 简单的 HTML 验证器
- 如何在 html 页面中插入 cgi 应用程序的输出?
- 在 C++ 中编写解析器来解析给定的 HTML 实体
- 使用 ReadTheOrg 将识字程序导出为 HTML 时保留源块的内容
- 当我使用 QDomDocument 解析 html 数据时,如何保留 "?
- 如何使用 libcurl 在本地 IP 上获取 HTML?
- 通过 c++ 中的套接字发送 html
- 如何使用utf-8编码在Qt5 WebEngineView中加载HTML页面?
- C++ libcurl - 无法从 URL 检索整个 html 内容
- 使用 C++ std::sregex_token_iterator 提取 HTML 注释
- 检查HTML 5视频元素是否正在获取帧
- 如何使用PHP将上传到本地主机的一个html文件重定向到磁盘上的另一个html文档
- Flex/Bison标记为HTML程序
- 如何在C++中正确地将我的语言字符输出到HTML文件中
- 使用 Lamda 从 QWebEngineView 中的 QWebEnginePage 获取 HTML
- 根据 C++ 中生成的随机数的值生成 Html RGB 值
- 正则表达式忽略 HTML 注释
- qprint 和 QTextDocument 中的表格边距使用 html 作为输入
- 如何从 doxygen 创建的 html 更改回代码
- 是否有提供可调整 dpi、可选文本和 CSS 支持的 HTML 到 PDF 渲染器?