vs2022报错莫名其妙,检查了代码没有问题。
错误 C2059 语法错误:“)”
错误 C2062 意外的类型“int”
错误 C2065 “r”: 未声明的标识符
都是这种保存,很奇怪我一开始运行还对继续完善代码之后就不对了。
去掉第二个int
1.把代码发出来
2.检查是否可能是编码问题
1.试试关掉项目,或者电脑重启
2.找到报错的那一行,试着修改一下
如果不行的话,可以把代码发上来,我在电脑上运行一下。
这个是错误段的
void Table::drawTableDate()
{
int begPos = m_curPage * m_rows;//数据开始的位置
int endPos = m_curPage * m_rows + m_rows;//数据结束的位置
settextcolor(BLACK);
for (int i = begPos, int r = 0; i < endPos; i++, r++)//行
{
const auto& line_date = split(m_dates[i]);
for (int k = 0; k < line_date.size(); k++)//列
{
int tx = m_x + k * m_gridW + (m_gridW - ::textwidth(line_date[k].c_str())) / 2;
int ty = m_y + r * m_gridH + 5;
outtextxy(tx, ty, line_date[k].c_str());
}
}
}
这个是整段,只在这个Table.cpp报了错
#include "Table.h"
#include"Configure.h"
#include<iostream>
Table::Table()
{
m_prevBtn = new PushButton("前一页");
m_nextBtn = new PushButton("下一页");
m_firstBtn = new PushButton("第一页");
m_lastBtn = new PushButton("结尾页");
}
Table::Table(int row, int col):Base(0,0,0,0)
,m_rows(row),m_cols(col)
,m_curPage(0),m_maxPage(0),m_extraPage(0)
{
}
Table::~Table()
{
delete m_prevBtn;
delete m_nextBtn;
delete m_firstBtn;
delete m_lastBtn;
}
void Table::setRowCount(int row)
{
m_rows = row;
}
void Table::setColCount(int col)
{
m_cols = col;
}
void Table::setHeader(const std::string& header)
{
m_header = header;
m_cols = 6;
//求出文字的宽度和高度
m_tw = ::textwidth("计算机1401");
m_th = ::textheight(m_header.c_str());
//求出格子的宽度和高度
m_gridW = m_tw + 10;
m_gridH = m_th + 10;
//求出表格的宽度和高度
m_w = m_gridW * m_cols;
m_h = m_gridH * (m_rows + 1);
}
void Table::insertDate(const std::string& date)
{
m_dates.push_back(date);
updatePage();
}
void Table::show()
{
drawTableGrid();
drawTableDate();
}
void Table::drawTableGrid()
{
setlinecolor(BLACK);
//画横线
for (int i = 0; i <= m_rows; i++)
{
line(m_x, m_y + i * m_gridH, m_x + m_cols * m_gridW, m_y + i * m_gridH);
}
//画竖线
for (int i = 0; i <= m_cols; i++)
{
line(m_x + i * m_gridW, m_y, m_x + i * m_gridW, m_y + m_rows * m_gridH);
}
if (m_maxPage > 0)
{
drawButton();
}
}
void Table::drawButton()
{
m_prevBtn->move(m_x, m_h + 30);
m_nextBtn->move(m_prevBtn->x() + m_prevBtn->width(), m_prevBtn->y());
m_firstBtn->move(m_nextBtn->x() + m_nextBtn->width(), m_nextBtn->y());
m_lastBtn->move(m_firstBtn->x() + m_firstBtn->width(), m_firstBtn->y());
m_prevBtn->show();
m_nextBtn->show();
m_firstBtn->show();
m_lastBtn->show();
}
void Table::drawTableDate()
{
int begPos = m_curPage * m_rows;//数据开始的位置
int endPos = m_curPage * m_rows + m_rows;//数据结束的位置
settextcolor(BLACK);
for (int i = begPos, int r = 0; i < endPos; i++, r++)//行
{
const auto& line_date = split(m_dates[i]);
for (int k = 0; k < line_date.size(); k++)//列
{
int tx = m_x + k * m_gridW + (m_gridW - ::textwidth(line_date[k].c_str())) / 2;
int ty = m_y + r * m_gridH + 5;
outtextxy(tx, ty, line_date[k].c_str());
}
}
}
void Table::updatePage()//ctrl+K+O直接跳转cpp
{
if (m_rows >= m_dates.size())
{
m_maxPage = 0;//从0开始
m_extraPage = m_dates.size();
}
else
{
m_maxPage = m_dates.size() / m_rows;
m_extraPage = m_dates.size() % m_rows;
}
}
void Table::eventLoop(const ExMessage& msg)
{
m_prevBtn->eventLoop(msg);
m_nextBtn->eventLoop(msg);
m_firstBtn->eventLoop(msg);
m_lastBtn->eventLoop(msg);
if (m_prevBtn->isClicked())
{
if (m_curPage != 0)
{
m_curPage--;
}
}
if (m_nextBtn->isClicked())
{
if (m_curPage < m_maxPage)
{
m_curPage++;
}
}
if (m_firstBtn->isClicked())
{
m_curPage = 0;
}
if (m_lastBtn->isClicked())
{
m_curPage = m_maxPage;
}
}
std::vector<std::string> Table::split(std::string str, char separator)
{
std::vector<std::string> res;
for (size_t pos = 0; pos != std::string::npos;)
{
//查找指定分割字符的位置
pos = str.find(separator);//size_t 类型表示C中任何对象所能达到的最大长度,它是无符号整数。
//取出字符串
res.push_back(str.substr(0, pos));
//把剩下的字符串保存到str
str = std::string(str.c_str() + pos + 1);
}
return res;
}
不知道你这个问题是否已经解决, 如果还没有解决的话: