|
ptr_Electron wrote: I dont want to implement logging in the same project as it will hit performance.
I was involved in a C++ project years ago. Unix based. Performance was a contractual requirement.
The architect was sure that logging was a performance problem.
So we removed logging.
Absolute zero impact on performance.
And that was back when spewing stuff to a console (stdio) could impact performance.
If you have a performance problem then you need to address the requirements and design first before looking for problems in the implementation and technologies.
ptr_Electron wrote: which has the mechanism to Log from C++ to C# code please
Every logging library that I have seen for at least the past 10 years if not longer uses pluggable designs. Which means if the plugs that are already available do not meet your needs then you can create your own. However at least when I looked some already supported remote logging plugs.
|
|
|
|
|
#include <iostream>
using namespace std;
int main(){
char c;
cin.get(c);
while(c != '\n'){
cout << c ;
cin.get(c);
}
}
int the code above shouldn't cout << c print every charecter i put in cin.get() in loop ?
Quote: while(c != '\n'){
cout << c ; //displays the charecter on screen
cin.get(c); //get another charecter
}
instead it print the string i enter collectively, for ex.
Quote:
input : "Jhon simon"
output : "Jhon simon"
please explain
Thank you
|
|
|
|
|
Your explanation is a bit unclear. If the "input:" and "output:" are the same, what exactly is the issue?
With limited information, the only thing I can suggest is:
cout << c << std::flush;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
No, it prints each character as you type it.
|
|
|
|
|
Google "cout buffering" for an explanation.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
cin.get() does not read individual keystrokes -- the input is buffered by the terminal until you hit Enter, then all of the input is sent to the program at once.
To read individual keystrokes, you'll have to rely on a third-party tool like GNU's ncurses library.
|
|
|
|
|
I use the CListCtrl to display a list of grouped properties. Each of these groups should be described by an explanatory text. That's why I entered longer texts as subtitles for the groups.
If the subtitle is short enough that it fits in one line, then everything looks fine.
However, if the subtitle is longer than one line, it is wrapped at the width of the list control. Unfortunately, the wrapped lines are then superimposed by the following contents of the list.
For example, the content of the items of the group overwrite the wrapped subtitle. When the group is collapsed, the subtitle is superimposed by the following groups.
See also the examples in the following Screenshot:
- Group 1 has a short subtitle and all looks fine.
- Group 2 has a log subtitle, which is overwritten by the contents of the items.
- Group 3 is collapsed and the wrapped subtitle is overwritten by the content of group 4.
Is there a way to expand the area for the subtitles?
Regards,
Friedbert
|
|
|
|
|
How can I do this in a smarter way in regular C-programming, without having an init function that initializes the values?
struct myStruct_s {
int myInt;
Bool_t myBool;
EventCallback_t myEventCallback;
};
#define DESIRED_ARRAY_SIZE (5)
static struct myStruct_s myArray[] = {
#if 1 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 2 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 3 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 4 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 5 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 6 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 7 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 8 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 9 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 10 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 11 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 12 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 13 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 14 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 15 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 16 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 17 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 18 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 19 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
#if 20 <= DESIRED_ARRAY_SIZE
{0xABCD, TRUE, NULL},
#endif
};
modified 6-Apr-18 7:29am.
|
|
|
|
|
Please edit the above, and remove all that formatting. People here can read normal font sizes quite well.
|
|
|
|
|
I didn't use any formatting. The forum has a bug, it does weird things to the formatting if you start a line with either #define of #if (try for yourself).
|
|
|
|
|
If you know HTML and want to insert HTML tags manually when posting (besides using the options on top of the editor window) have a look at the bottom of the page when posting a message. There are two options:
"Treat my content as plain text, not as HTML"
and
"Use Markdown formatting"
When both are unchecked nothing will be auto formatted.
The first option can be also changed on your profile settings page in the Forums tab.
|
|
|
|
|
|
When using C++ and all members should be initialised with the same value you can provide a constructor:
struct myStruct_s {
int myInt;
Bool_t myBool;
EventCallback_t myEventCallback;
myStruct_s() : myInt(0xABCD), myBool(FALSE), myEventCallback(NULL) { }
};
static struct myStruct_s myArray[DESIRED_ARRAY_SIZE];
|
|
|
|
|
I forgot to mention, I'm programming in regular C.
|
|
|
|
|
Then I know only four ways:
- Like you have done with multiple preprocessor
#if statements.
- Using weird preprocessor macros to create a loop.
- Initialising by code using a loop.
- Writing a helper program that creates a file with the relevant code lines that can then be included in a source file or even linked when declaring the struct as extern. The helper program must then be executed by the make file (or a corresponding custom build option when using an IDE) before compiling.
|
|
|
|
|
One approach is to not bother; just initialize the array to what the maximum size could be and then store the actual size in a static variable.
If this isn't time critical, just do it dynamically. Or, make sure the default values is zero and do a memset early on.
In this case, they're all the same, so doing a quick loop early on solves the problem.
|
|
|
|
|
#include <iostream>
#include <string>
using namespace std;
int main(){
const char *ptr = "tarun" ;
cout << name << endl ;
return 0;
}
in the above code if i assign a string literal to a const char*
Quote: const string *name = "tarun";
it prints the string but the same with string gives error that
Quote: cannot convert ‘const char’ to ‘const string
so it means any string literal is a const char (which i think is a rvalue),
but it is a collection of characters, so how is it a char ? and if it is a char then why it is called string literal ?
please explain.
Thank you.
|
|
|
|
|
Tarun Jha wrote: n the above code if i assign a string literal to a const char*
Quote: const string *name = "tarun";
You may want to change it to
const string name = "tarun";
|
|
|
|
|
Tarun Jha wrote: ...but it is a collection of characters, so how is it a char ? The variable ptr is a pointer to a collection of char -acters, be it 1 or 100.
Tarun Jha wrote: ...then why it is called string literal ? Like anything holding quotation marks apart, they are literally those characters. They haven't been modified, translated, obtained from some other place, coerced, etc. If you look inside the compiled file, you will see those characters, literally.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
To me you are sort of asking a strange question well outside the literal string part, so lets just check you understand some basics
First a string is class or if you want an object it has constructors, destructor and methods it isn't just an array of characters.
string - C++ Reference[^]
You can't remotely equate those two lines as anything similar, do you understand that?
So with a string class when you declare it as a const (like your commented out) what are you expecting it will do?
So you are clear you are asking for a constant pointer to an object and trying to set some literal string to that object.
This may also help understand Victors response and David deals with the literal part.
The point here is you can only create a string when it matches one of the constructor types of the class.
What constructor functions exist controls how you can create it.
Here is the examples of showing the seven standard constructor methods for the class
string::string - C++ Reference[^]
The situation with just a character array is very different
const char *ptr = "tarun";
We have a simple array of characters that can never be changed AKA they are constant
Everything from a C to a C++ compiler understands the later because it's very trivial.
In vino veritas
modified 3-Apr-18 23:11pm.
|
|
|
|
|
Hi. I need to use OpenCV in some project, and I noticed that I have to compile myself OpenCV library.
So, I have downloaded the latest version from here: Releases - OpenCV library[^]
and I have generated the project file for VS2008, with CMake (using Windows 1064bit). All of these steps have been completed without any error. The problem begin when I have tried to compile the library itself ... I got a lot of errors:
...
...
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(356) : error C2065: 'uint_fast64_t' : undeclared identifier
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(358) : error C2065: 'uint_fast64_t' : undeclared identifier
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C2146: syntax error : missing ';' before identifier 'cvRound64'
...
...
Of course, I have read the tutorials about compiling OpenCV, seem to be ok how I get the steps ... but the errors persist ... if you have some experience with OpenCV, could you help me ?
Thank you.
|
|
|
|
|
Did you include the <stdint.h>?
|
|
|
|
|
For the moment I am compiling the OpenCV library, and I didn't edit any source code. Perhaps I put too less information regarding the errors:
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2065: 'uint_fast32_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2146: syntax error : missing ';' before identifier 'vv'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(190) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(314) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(321) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2146: syntax error : missing ';' before identifier 'vv'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(332) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(348) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(352) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(354) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(356) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(358) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C2146: syntax error : missing ';' before identifier 'cvRound64'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(47) : error C2365: 'base64::base64_encode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : see declaration of 'base64::base64_encode'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(49) : error C2365: 'base64::base64_decode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : see declaration of 'base64::base64_decode'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(51) : error C2365: 'base64::base64_valid' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : see declaration of 'base64::base64_valid'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\..\..\sources\modules\core\src\umatrix.cpp(482) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(137) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=char
1> ]
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C2146: syntax error : missing ';' before identifier 'globalDetectTininess'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(47) : error C2365: 'base64::base64_encode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : see declaration of 'base64::base64_encode'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(137) : error C2064: term does not evaluate to a function taking 4 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2143: syntax error : missing ')' before 'const'
1>..\..\..\sources\modules\core\src\softfloat.cpp(97) : error C2448: 'raiseFlags' : function-style initializer appears to be a function definition
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(154) : error C2064: term does not evaluate to a function taking 3 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(49) : error C2365: 'base64::base64_decode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : see declaration of 'base64::base64_decode'
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C2146: syntax error : missing ';' before identifier 'globalRoundingMode'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(163) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=uchar
1> ]
1>persistence_types.cpp
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2065: 'uint8_t' : undeclared identifier
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C2086: 'const int cv::uint_fast8_t' : redefinition
1> ..\..\..\sources\modules\core\src\softfloat.cpp(81) : see declaration of 'cv::uint_fast8_t'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2143: syntax error : missing ')' before 'const'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(180) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=uchar
1> ]
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(51) : error C2365: 'base64::base64_valid' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : see declaration of 'base64::base64_valid'
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(100) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=char
1> ]
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(100) : error C2064: term does not evaluate to a function taking 4 arguments
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(117) : error C2064: term does not evaluate to a function taking 3 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(167) : error C2146: syntax error : missing ';' before identifier 'f32_to_i32'
and it count for ever ...
|
|
|
|
|
Where should I insert this header ?
|
|
|
|
|
If you are using precompiled header then in stdafx.h.
Otherwise - at the begin of the .hpp file that needs these type definitions (uint_fast64_t and so on)
|
|
|
|
|