Function Constructor?

Does anyone know why FPS() wants a contructor, or how to use % properly?
std::string s = "FPS-%",convertInt(FPS());

Thanks in advance.
Heres the error log if it helps.

error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'int' to 'const std::basic_string<_Elem,_Traits,_Ax> &'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> Reason: cannot convert from 'int' to 'const std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
What does your FPS() do? What's its prototype? What is the prototype of convertInt()?
And finally why do you write a comma here?
std::string s = "FPS-%",convertInt(FPS());

And please show me code.
ah ok
This is the whole code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "stdafx.h"
//#include <GL/GL.h>
#include <GL/glut.h>
#include <sstream>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <sstream>
int framecount = 0;
int tFPS;
int st = 0;
std::string convertInt(int number)
{

   std::stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
int FPS()
{
	framecount++;
	if(clock()-st>=1000)
	{
		tFPS = framecount;
		framecount = 0;
		//tFPS = framecount;
		st = clock();
		//system("PAUSE"); 
	}	
	return tFPS;
}
void text()
{
	glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0,200, 0.0,200);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(0.0, 1.0, 0.0); // Green
glRasterPos2i(50, 200-10);
std::string s = "FPS-%",convertInt(FPS());
void * font = GLUT_BITMAP_9_BY_15;
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
{
    char c = *i;
    glutBitmapCharacter(font, c);
}
	glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
}


void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	text();
glFlush();
glutPostRedisplay();

}
int _tmain(int iArgc, char* cppargv[])
{
	glutInit(&iArgc,cppargv);
	glutCreateWindow("Framerate");
	glutDisplayFunc(display);
	glutMainLoop();
}
Last edited on
Use + instead of ,
std::string s = "FPS-%" + convertInt(FPS());
Topic archived. No new replies allowed.