小编Tsa*_*ras的帖子

控制OpenGL应用程序中的FPS限制

我试图找到一个可靠的方法,能够准确设置我希望我的OpenGL应用程序在屏幕上呈现多少FPS.我可以通过休眠1000/fps毫秒在某种程度上做到这一点,但这没有考虑渲染所需的时间.哪种是将fps限制在所需数量的最一致方法?

opengl 3d frame-rate

11
推荐指数
4
解决办法
1万
查看次数

ifstream getline问题

我的代码打开一个文本文件,计算行数,分配一个数组来存储所有行,然后调用一个函数来用每行填充这个数组.此函数file.getline调用返回空字符串:

这是代码:

typedef char* line;
Run Code Online (Sandbox Code Playgroud)

...

char* filename=new char[256];
cout << "Type a file name: " << endl;
cin.ignore();
cin.getline(filename,255);

ifstream iFile(filename);

int nLines=CountLines(iFile);

line* LineArray = new line[nLines];
ReadLines(LineArray,iFile);
Run Code Online (Sandbox Code Playgroud)

CountLines功能:

int CountLines(ifstream &file)
{
line templine=new char[64];
int nLines=0;

while (!file.eof())
{
    file.getline(templine,64);

    if (*templine != '\n')
        nLines++;

}
delete [] templine;

return nLines;
}
Run Code Online (Sandbox Code Playgroud)

这工作正常.然而,ReadLines没有:

void ReadLines(line* LineArray, ifstream &file)
{
    line templine=new char[64];

file.seekg(0,ios::beg);

int i = 0;
while (!file.eof())
{

    if (*templine != '\n')
    {
        LineArray[i]=templine; …
Run Code Online (Sandbox Code Playgroud)

c++ getline ifstream

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

3d ×1

c++ ×1

frame-rate ×1

getline ×1

ifstream ×1

opengl ×1