Click here to Skip to main content
15,889,909 members
Everything / Programming Languages / C++98

C++98

C++98

Great Reads

by Andreas Gieriet
HTML page with all syntax/grammar productions of C++98/C++11
by Intel
This earthquake detector application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.
by goranorsander
A class template for specializing fundamental types
by stevemk14ebr
A modern, universal, c++ hooking library.

Latest Articles

by goranorsander
A class template for specializing fundamental types
by Marcell Lipp
This tip shows how to unit test a private function in C++.
by Alexey Shtykov
A few words about function templates
by Intel
This earthquake detector application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.

All Articles

Sort by Score

C++98 

6 Jul 2016 by Jochen Arndt
You are passing the vector by value to your Divisor function:void Divisor(int n, vector vec)When calling the function, a new vector instance is created and filled with the data of the passed vector. But the content of the passed vector is not changed.To change the content of the...
13 Sep 2016 by barneyman
you've answered your own questionit's 0x43 because showbase inserts the 0xYou're not using showbase on the octal cout - if you were, line #2 would be 0103(and it's an 'x', not an '*')
18 May 2023 by CPallini
See, for instance: https://stackoverflow.com/questions/12050777/how-to-return-memory-from-process-to-the-os[^]
12 Feb 2012 by Andreas Gieriet
HTML page with all syntax/grammar productions of C++98/C++11
25 Jun 2016 by OriginalGriff
Indentation helps a lot when you look at code: it means you can see what is goign on a lot more clearly...But a quick glance says that the swap function:void swap(int *i,int *k){int j;// js any temperory element*i=*k;*k=j;}Is not going to work!What value do you put in k each...
4 Jul 2016 by Jochen Arndt
You are accessing an unitialised variable (the iterator itr1) with the dereference operator (*).To let the iterator point to a specific vector element add the index to the iterator pointing to the begin of the vector:itr1 = vec.begin() + 4;vec.erase(itr1);Alternatively use advance -...
23 Feb 2017 by Jochen Arndt
As far as I understand you want to execute commands from within your app like the ADB command line client.Then I would have a look at the ADB client sources to see how that communicates with the server background process. Together with the GitHub - cstyan/adbDocumentation: Better...
27 Mar 2017 by Intel
This earthquake detector application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.
19 Jun 2017 by CPallini
If you need to insert blanks somewhere in the string (like your example suggests) then the string::insert method ( see string::insert - C++ Reference[^]) is your friend: #include #include using namespace std; int main() { string s = "hello"; s.insert(1, 1, ' '); ...
4 Jul 2017 by OriginalGriff
OK: x is (presumably) an integer, which means it is a collection of (say) 32 bits which make up the number: the rightmost bit is the least significant, and the left most is the most significant, and they are numbered from (normally) bit 0 to bit 31, where the index indicates the power of two...
16 Oct 2017 by Jochen Arndt
See the documentation to know which header file has to be included: exit - C++ Reference[^] or exit Function | Microsoft Docs[^] (for Visual Studio): Quote: The exit function, declared in the standard include file STDLIB.H, terminates a C++ program.
13 Jul 2018 by Jochen Arndt
There is no type long float in C/C++. There are float, double, and long double. Note that long double is the same as double with some compilers and libraries like with Visual C++.
13 Jul 2018 by Richard MacCutchan
You can open an existing file with the append option to add more information. If the file does not exist then just use the create for writing option. The documentation for CFile, and also open, fopen and CreateFile gives full details.
8 Feb 2019 by Thomas Daniels
You need to include : #include
3 Jan 2020 by goranorsander
A class template for specializing fundamental types
9 Apr 2021 by CPallini
Try #include #include #include using namespace std; int main() { struct staff { int id; string name; string cls; }; vector s = { {234, "Mark", "Biology"}, {3455, "Mitch",...
2 Nov 2021 by OriginalGriff
We can't help you: we have no idea where you are getting the error, when it occurs, what you do to get it, or what code might be involved. This is a site for software development problems: you write code, we try to help you fix it. But even if...
27 Jun 2022 by merano99
For UTF-8 you code this: DWORD dwBytesWritten = 0; BOOL bErr = 0; TCHAR *fname = TEXT("A_Unicode_WriteSTuff_天_file.txt"); HANDLE hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);...
16 Sep 2022 by Rick York
Your code is incomplete. We don't know what the types of some of your data is like g_DeliveryRpt. I would add another call to log after the mutex is acquired like this : string l_Resp( "Code For Project" ); log("String formation done...
18 Dec 2013 by Buddhi Chaturanga
I defined source & header -"MathCore.h" & "MathCore.cpp"MathCore.h as below code :#ifdef MATHCORE_EXPORTS#define MATHCORE_API __declspec(dllexport)#else#define MATHCORE_API __declspec(dllimport)#endifMATHCORE_API bool isPowOf_Two(unsigned int n);MATHCORE_API bool...
18 Dec 2013 by CPallini
I would use CL /O2 t.cpp MathCore.lib
18 Dec 2013 by Richard MacCutchan
See http://msdn.microsoft.com/en-us/library/610ecb4h(v=vs.100).aspx[^] and also the /OUT option at http://msdn.microsoft.com/en-us/library/y0zzbyt4(v=vs.100).aspx[^].
4 Mar 2016 by Richard MacCutchan
You cannot create a .com program directly from the assembler (including the fact that the source does not support it). The output should have a .exe extension.
4 Mar 2016 by stackprogramer
i had a silly wrong!!i completed answer my friend after thinking i concluded that int 0x80 is not in windows, it should be for linux.Richard MacCutchan thanks very much.cordially your stackprogramer
7 Mar 2016 by Richard MacCutchan
Class methods in MFC all begin with an uppercase letter, as suggested by Suvendu above. The first place to look for issues like this is the MSDN documentation pages[^].
13 Jun 2016 by Patrice T
In C and C++ language, you can't define a function inside another one.You must move print outside of insert_Indentation is here to help you to read your code. proper use of indentation prevent this kind of problem.I recommend the usage of a programmer's editor like NotePad++.Notepad++...
22 Jun 2016 by Member 12599256
bool prime_number(int z);is a function that return a boolean, and in your code you want to set true/false to that function ?prime_number(k)=false;that is not possible.
22 Jun 2016 by Patrice T
bool prime_number(int z);Is a function prototype, not an array.You need to learn deeper the basicsThe C Programming Language - Wikipedia, the free...
22 Jun 2016 by Sergey Alexandrovich Kryukov
It's not "1value", it's "l-value", where 'l' means "left". This is explained, for example, here: Lvalues and Rvalues (Visual C++).Doesn't it make sense? :-)—SA
25 Jun 2016 by Richard MacCutchan
p_array=new int[n]; p_matrix=new int[n]; cin >> n;That will never work how you expect. You allocate two arrays based on the value of variable n before you have assigned a value to it. You need to go through your code carefully to check the logic.
6 Jul 2016 by OriginalGriff
"there is some error" tells us nothing - anything could be happening and we have no idea what! Saying that is like your car breaking down in the middle of nowhere, then when you call the garage just saying "it broke!" and ending the call. How long do you think you will be waiting before they...
6 Jul 2016 by Patrice T
The way you calc the GCD is complicated and a waste of resources.Collecting all divisors of a number takes a lot of time.Bug: You forgot that n is divisor of itself !void Divisor(int n,vectorvec){ for(int i=1; i+1; i++)> { if(n%i==0) { ...
16 Aug 2016 by Patrice T
This is HomeWork, so it is your task to produce a program.When you ask someone else a question about your HomeWork, at least post the real statements of the problem. It will avoid crazy situations like this one, where your statements have 5 contradictions or inconsistencies.Ex: for 4321,...
4 Sep 2016 by Patrice T
My best advice:Pass exams with flying colors. It is the best thing you can do to prove him he is a good teacher and you a good student.We can't give you other advice because you are the one that know him the best, if you have no idea, how can we have one that will interest him.Remember...
21 Sep 2016 by Andrea Simonassi
Hi, I am not up to date with latest c++ and how it is strongly typed nowadays: ConceptThe concept is that the memory representation changes depending on the declaring type.Char is usually defined as an 8 bit memory cell, int is usually defined as 32bit or 64bitchar x =...
22 Oct 2016 by Member 12632487
I know the use of NEW keyword but i am confuse that what is main perpose of new keyword?Some time we can do the same thing with other methods which we do with new keyword so need of clarification.below is the exampleI have created pointer object obj of class person and pass the address of...
22 Oct 2016 by Suvendu Shekhar Giri
The first question that comes in to mind, is Google banned in your region?Quote:Allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the object. new operator in C++[^]Hope, it helps :)
12 Dec 2016 by KarstenK
For such calculation you must create an array.Global materials[8];//zero indexed //first as sample materials[0].Material_name="Cobalt"; materials[0].grade= "A"; materials[0].price_per_kg = 6.5;Price=global[num].price_per_kg *weight; //access to array of structs and its member...
2 Jan 2017 by Albert Holguin
Statics are more "similar" than "equivalent" between C/C++....Here's an explanation of what you're seeing:Initialization of static variables in C - GeeksforGeeks[^]The initialization order in C means that the static must be defined from a constant (it doesn't imply that the value has...
19 Jan 2017 by john5632
Hello,If constructor is throwing any execpetion after allocating some memory (using new) on heap then how can we free that allocated memory.What I have tried:If constructor is throwing any execpetion after allocating some memory (using new) on heap then how can we free that allocated...
19 Jan 2017 by Jochen Arndt
Just handle the exceptions inside a catch all block and rethrow the exception:MyClass::MyClass() : member1(NULL) ,member2(NULL){ // Initialise all pointers to memory to be allocated with NULL here or // as shown above. // Then delete can be safely called for them. ...
20 Feb 2017 by Jochen Arndt
As already mentioned conio.h is a compiler suite specific header file introduced by Turbo C for MS-DOS which has been later adapted also by Microsoft for their C compilers.For similar functions on Linux you can use a curses library like Announcing ncurses 6.0 - GNU Project - Free Software ...
14 Mar 2017 by OriginalGriff
Try:#include int main(){ printf("***** * * *** ***** *****\n"); printf(" * ** * * * * * *\n"); printf(" * * ** * * * *****\n"); printf("***** * * *** ***** * *\n"); return 0;}
22 Mar 2017 by Garth J Lancaster
Its not clear what your sequence is .. but if you look at this { for ( int k = 0; k
22 Mar 2017 by Jochen Arndt
The setting applies to the process and therefore also to DLLs loaded by the process.But the functions within the DLL might not be able to handle addresses beyond 2 GB. You have to ask the supplier of the DLL.
5 Apr 2017 by OriginalGriff
First off, you need to start by looping on the first user choice: if they enter an "Invalid input" then it complains, but lets them play anyway - that's bad. Add a "valid entry" variable, and loop until you get one. Second, you need a second loop for the user input of the actual game. This...
7 Apr 2017 by Jochen Arndt
There are two errors in your code: You are never calling CreateGrid() (Grid::grid is empty) The Grid::grid vectors are never allocated To fix the first error call CreateGrid() in the constructor: Grid(cv::Mat _map){ map = _map; gridx = map.cols; gridy = map.cols; ...
18 Apr 2017 by OriginalGriff
Quote: I want the program on computer allocation (allotment) system in c++ We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and...
21 Apr 2017 by Jochen Arndt
This will never work as expected. You are storing the string in m_strParamval. This string will be updated whenever you insert a new item. So you would always get the string for the last added item. But more important, the LPARAM values might not point to a valid string anymore. m_strParamval...
25 Apr 2017 by Jochen Arndt
See the documentation: DragQueryFile function (Windows)[^]. Call DragQueryFile first with iFile set to 0xFFFFFFFF. That call will return the number of file names. Then use a loop to get each file name: UINT fileCount = DragQueryFile(hDrop, 0xffffffff, NULL, 0); for (UINT i = 0; i
10 Jun 2017 by OriginalGriff
Two problems I see: both of which should prevent the code compiling. 1) null is backslash zero, not slash zero:b[j]='/0'; should be:b[j]='\0'; 2) You are missing a semicolon on this line: cout
11 Jun 2017 by OriginalGriff
Winforms isn't like a console app, there is a "main" proc, but it's not where you put most of your code (if any). And there isn't a loop in the sense you mean! Instead it's job it to process Windows messages, and call the appropriate function when a particular message is received - and it...
11 Jun 2017 by Richard MacCutchan
See EFNet #Winprog[^] and Win32 Programming - FunctionX[^] for some useful tutorials.
14 Jun 2017 by jeron1
Take a look at this[^] thread, it deals with a similar question.
30 Jul 2017 by Kornfeld Eliyahu Peter
The problem i that you missing the definition part (you only have the declaration part) and that leads to an incomplete type... You can fix it like this... class Animal { public: static int ID; }; int Animal:ID; int main() { Animal::ID = 5; printf("%d \n", Animal::ID); return 0; } A much...
3 Aug 2017 by Jochen Arndt
The error is in the teacher constructor accepting parameters: teacher(string n,int a,string c) { student(n,a); course=c; } There you are creating a local student instance from the parameters but that goes out of scope when leaving the constructor letting the members unitialised. You...
8 Aug 2017 by CPallini
If you need to serialize[^] the struct then memcpy[^] is the way to go student s; char a[100]; memcpy(a, &s, sizeof(s)); [update]Fixed a blunder, thanks to K5054[/update].
28 Aug 2017 by Jochen Arndt
The second version will generate a compiler error. The compiler sees an access to Base::fun() which is denied because that is private. In the first version it is allowed because the Base::fun() is public. Because the function is virtual, the compiler will not generate code to call the function...
13 Sep 2017 by Patrice T
You check some user input against 'Y' and 'N' but user input can be 'y' or 'n', in which case your test fail. Solutions: - you need to force user to input uppercase. - add a check for 'y' and 'n' too. - test with uppercase if user input; by using the toupper function. If user input can only be...
23 Sep 2017 by OriginalGriff
Solution 1 is correct, and will work: however do remember that that code will generate a local variable: the array of chars will be on the stack, not the heap: it will only exist until you return from the current function, and cannot be returned to the calling function in any way without causing...
24 Sep 2017 by OriginalGriff
Write another function: FindNext. Hand it the array and it's size, the value to look for, and the index to start at. If you find another example, return the index. If you don't, return -1. Then loop calling that and printing minima until it can't find any more. But this is your homework, so...
24 Sep 2017 by Patrice T
Change int a, b, c, d; to double a, b, c, d; Your problem comes from the way C/C++ handle division of integers. c - What is the behavior of integer division? - Stack Overflow[^] division - How to divide 2 int in c? - Stack Overflow[^] c - Division result is always zero - Stack Overflow[^] c -...
7 Oct 2017 by Steve44
This might not be a solution since it is not clear, what you want to accomplish, please provide an example of "If brandList contains a,b,c, then result should look like x,y,z" But there are several obvious issues already, maybe this gives you a few hints how to proceed: Your index i is...
6 Nov 2017 by GKP1992
They want to make the code "Object-oriented" like. Think of the headers as a file that tells what the implementations of that class are supposed to do. It is a good idea use headers and implementations to keep the behavior of that particular class homogeneous across the application. For more...
7 Nov 2017 by KarstenK
It is convention in the language c and C++ to seperate code for better readability. In a h. file are the declaration of functions, classes and constants. And in the cpp-files is the implementation of the declared stuff of the header. Your WeatherMeasurement files are empty. It is your job to...
7 Nov 2017 by CPallini
A starter: Headers and Includes: Why and How - C++ Forum[^].
8 Nov 2017 by KarstenK
As it can be read in the famous README.TXT of this github upload: "The bad news: this code only compiles and runs on linux.". So you need some Linux and gcc and than run the makefile. digg trough the Getting Started section of the GCC for learning gcc or search some tutorials. Contact the...
11 Nov 2017 by KarstenK
That is a relly simple task, so I give you only some tips: use clearer var and function names, not x() use debug output (printf) in critical code pathes like function call and if statement (remove oe comment out when not more needed) write some test data, with simple array so you can debug your...
18 Dec 2017 by Jochen Arndt
You can use a vector - C++ Reference[^] to store and return multiple values: #include std::vector Circle::getAreas() { std::vector result; ifstream fin; fin.open("shape-in2.txt"); while(!fin.eof()) { char check; fin>>check; //...
18 Dec 2017 by Richard MacCutchan
Start by creating a class that deals only with values and calculations. The class constructor should take one parameter, the radius of the circle. You can then call a method to calculate and return the area. You can have another method that accepts the co-ordinates and shows the circle's...
2 Jul 2018 by CPallini
You have to parse the text. You may either use raw strtok[^] calls or a regex library. Please note, since C++ 11, regular expressions are part of the STL: - C++ Reference[^].
3 Jul 2018 by User 7429338
It looks like the function OnButton1() is the place where you are doing the resizing. You could either move modify the menu there, or return a status variable to indicate if the window is big or small. For example: CMenu* pMenu = GetMenu(); int isBig = OnButton1(); if(isBig) { ...
5 Jul 2018 by Richard MacCutchan
Your factorial routine does not look correct, and the while loop will only ever do one iteration. Factorial N is 1*2*3...*N. You also need to get rid of those two huge arrays, they serve no purpose. The logic for your program should be: Get number of tries DO Get next number Calculate...
5 Jul 2018 by Rick York
The color used to construct the *pBrush is the one that needs to be adjusted. You could make a color variable (COLORREF) a member of the RoundBtn class and set it to 220,100,220 in the class constructor. Then add a method to set the color member and you can have each button be a different...
8 Jul 2018 by OriginalGriff
Your structure will always be bigger than the pointer to it: if only because the actual node contains a pointer to the struct so it has to be at least the size of a pointer plus the size of the other elements. So yes, you must use sizeof(struct node) when you malloc the node itself. If you...
13 Jul 2018 by OriginalGriff
I'm sorry, but ... you probably aren't going to get what you want here (or anywhere else). Think about it: you admit to not having any realistic programming skills, and you want to make a multiplayer based browser game. That's complicated, very complicated - and the person who "helps" you will...
10 Nov 2018 by CesatAGS
Hi, i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine code dll project: __int64 RerturnLocalPlayer() { __int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX is function that return my player return player; } in my...
10 Nov 2018 by 11917640 Member
Int64 localp = RerturnLocalPlayer();
5 Dec 2019 by Richard MacCutchan
Console programs do not use the mouse, they are text based.
12 Apr 2021 by Greg Utas
It looks like the words to be grouped together are enclosed in quotation marks, so you'll have to add that to your parsing logic. When parsing within quotation marks, you'll have to get the next word and add it to the one you're working on after...
12 Apr 2021 by OriginalGriff
It's called CSV (Comma Separated Values) and if you do a quick Google you will find loads of examples / libraries which can read it: read csv c - Google Search[^] Personally, I wouldn't write my own - it's not a trivial job to get right because...
13 Apr 2021 by Richard MacCutchan
You have been given suggestions already at How do I read comma and quotation delimited file in C++?[^]. You need to check if a token starts with a double quote, and if so , ignore all separator characters until you find the closing quote. The...
13 Apr 2021 by OriginalGriff
As I said last time, don't write it yourself, there are plenty of examples out there. You are trying to be lazy and "Let the system do the work" for you, and with CSV that just won't work - you need to process the whole string intelligently, as...
3 May 2021 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
19 Apr 2022 by k5054
You can use SSL_get_rbio() and SSL_get_wbio() to get the read and write BIOS associated with an SSL connection. Alternatively instead of using SSL_connect(), you can use SSL_accept() which returns a BIO suitable for reading and writing.
25 Jun 2022 by merano99
I can't get the code sample to compile without further tricks. The compiler points out that you need a special code page for the special (chinese?) character. // warning C4566 : The character represented by the universal character name "\u5929"...
25 Jun 2022 by merano99
The questioner had stated that he uses Code:Blocks with MinGW under Windows. MinGW seems to have problems with UNICODE, other compilers like Visual-Studio or TDM-GCC realize at least under Windows with wchar_t. The C++ standard does not seem to...
5 Jul 2022 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
5 Jul 2022 by merano99
This question seems to be a very popular Homework. There also seems to be a solution for a fee....
22 Aug 2022 by Greg Utas
You can do this within the same program (process), but most platforms prevent one process from reading the data of another process. To do that, you'd have to use a system call to make the memory accessible to another process.
22 Aug 2022 by CPallini
Quote: Can a pointer access based on a known memory address? Yes, provided they are in the same process. If you need to access it from another process then you are out of luck.
16 Oct 2022 by merano99
The command system() creates a new process to handle the specified command. char cmd[10]; strcpy(cmd, "dir"); system(cmd); In most cases, this is neither performant nor useful. But of course you can start a process with C this way. You could...
19 Oct 2022 by Alexandrnn
#include #include int main() { system("dir"); puts((char*)stdin); } #include #include #include int main() { char cmd[10]; strcpy_s(cmd, 10, "dir"); system(cmd); puts((char*)stdin); }
20 Oct 2022 by Rick York
Have you investigated the RegDeleteKeyExA function (winreg.h) - Win32 apps | Microsoft Learn[^] ? Here is another sample : Deleting Registry Key with Subkeys Win32 C program example[^]
16 Nov 2022 by OriginalGriff
Auto commit mode means that as soon as a statement is executed, Commit is called on the connection. At a guess - and I have no access to your system for testing - the setSchema call throwing an error probably means that the DB name...
5 Jan 2023 by Member 8840306
I am new in QT using C++ 98.I am setting the stylesheet in QT from of 5 label and 5 button using this class function Code 1(working), void Display::setting_Style() { ...
5 Jan 2023 by Michael Haephrati
There are a few issues with the code you provided in Code 2: In the first loop, you are trying to access the widget member of the signalMapper object, but this object does not have a widget member. You need to use MyForm::getMyForm() to get a...
13 Jan 2023 by Richard MacCutchan
Your fwrite call parameters are incorrect: fwrite(name, sizeof(name) , sizeof(name) , fptr); That means you will try to write 50 characters 50 times. It should be: fwrite(name, sizeof(name) , 1, fptr); // write the name once only And the...
18 May 2023 by OriginalGriff
What did you expect? You are creating 10,000,000 streams, and adding them all to a list: list l1; for(int i=0;i
20 May 2023 by steveb
clear() in STL containers does not re-shrink the allocated storage. If you call capacity(), you will get the real allocated storage size on an emptied container. If you must release the allocated storage you would need to call swap() function...