Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • Help me to decipher the error messages

    help database
    9
    0 Votes
    9 Posts
    54 Views
    L
    I think it's the same cookie under a different name. "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
  • Creating an update function for my game

    game-dev graphics help tutorial question
    7
    0 Votes
    7 Posts
    45 Views
    L
    void UpdateGame() { MessageBox(hWnd, "Doing the update", "Game", MB_OK); } :laugh: :laugh:
  • Loop thru two dimensional array - edited

    help question database hardware
    8
    0 Votes
    8 Posts
    56 Views
    L
    Yes, pretty much similar code. ..and the idea of "variable count ", I will eventually have a file where I will keep the data and will add to it as required - sort of database . I messed up a little and had the main loop in the array... It has been great "discussion" and it helped a lot... Thanks PS I may post the final version ,if anybody cares. Right now it is lot of "cut and paste" to put it in code which actuality does puts menu /submenu into main code.
  • Adding "checkable " in Qt QMenu / QAction using C++ partially fails

    c++
    5
    0 Votes
    5 Posts
    27 Views
    L
    The issue was /is the relations between QMenu and QAction...I did solved this by looking at many similar examples. But as told many times - posting it here was my mistake, lesson learn. Thanks.
  • Please - explain the C++ code / function

    c++
    18
    0 Votes
    18 Posts
    96 Views
    J
    It takes all kinds. :sigh: "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
  • memory allocation failure

    c++ performance question
    6
    0 Votes
    6 Posts
    42 Views
    Mircea NeacsuM
    Colour me not impressed! As long as you take the free option, I guess you didn't loose much, except maybe some time. Also there is the question of getting bad programming habits, but those can be fixed over time. These days there are many free online course from very reputable sources like MIT OpenCourseWare | Free Online Course Materials[^]. You might want to take a look at some of them. Mircea
  • catching a divide-by-zero error

    help tutorial question
    6
    0 Votes
    6 Posts
    40 Views
    D
    In Windows, there are additional, O/S-level exceptions, that provide this sort of information. Look for "Structured Exception Handling". If you use MSVC, you may use the _set_se_handler function in main() and in the main function of each thread to convert Structured Exceptions to C++ exceptions. There may be similar O/S- and compiler-specific methods in other environments. Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
  • 0 Votes
    3 Posts
    21 Views
    D
    One more detail - on Windows, you must open the file in "binary" mode using the O_BINARY flag (for open) or "rb" (for fopen). Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
  • !file trickiness

    question performance help
    4
    0 Votes
    4 Posts
    18 Views
    L
    mike7411 wrote: Can someone help me understand how this line works: the statement: if (!file) means if the variable file equals null then ... But you have already instantiated file with the line: ifstream file; So it is very unlikely that file will be null. The open method sets the failbit status if the open fails, and that is what you need to test. If you use STL classes then you must follow the STL rules, not the old C-style ones. See std::basic_ifstream<CharT,Traits>::open - cppreference.com[^] for full details.
  • outputting Δέλτα

    c++ debugging help question
    2
    0 Votes
    2 Posts
    10 Views
    D
    First things first, you're ignoring the return value of _setmode. If it's -1, the call failed, but you'll never know. Second, after reading the documentation on _setmode and associated error links, it appears you cannot use cout with the mode of stdout switched to Unicode. You have to use wprintf instead: #include #include #include using namespace std; int main() { int r; r =\_setmode(\_fileno(stdout), \_O\_U16TEXT); if (r == -1) perror("Cannot set mode"); wprintf(L"\\u0394\\u03AD\\u03BB\\u03C4\\u03B1\\n"); return 0; } CORRECTION: You CAN use COUT, but you must use the wide version of it, but note the L in front of the string being output. It MUST be there: #include #include #include using namespace std; int main() { int r; r =\_setmode(\_fileno(stdout), \_O\_U16TEXT); if (r == -1) perror("Cannot set mode"); wcout << L"\\u0394\\u03AD\\u03BB\\u03C4\\u03B1" << endl; return 0; } Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
  • sizeof not working

    question
    5
    0 Votes
    5 Posts
    41 Views
    J
    jschell wrote: if Stroustrop is the name then I would consider that better. Agreed. :) "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
  • deleting from a vector

    help c++ graphics tutorial question
    3
    0 Votes
    3 Posts
    24 Views
    Mircea NeacsuM
    As you guessed, erase invalidates all iterators on the container. Your problem is known as the Erase–remove idiom[^] There are different ways of solving it: 1. The "manual" way: auto pos = myVector.begin(); size_t i=0; while (pos != myVector.end()) { if (*pos ==3) { myVector.erase(pos); pos = myVector.begin() + i; } else { ++i; ++pos; } } 2. The "semi-automatic" way: auto pos = myVector.begin(); while (pos != myVector.end()) { if (*pos ==3) pos = myVector.erase(pos); //erase returns an iterator pointing to next element else ++pos; } 3. The "old fully automatic way": myVector.erase(std::remove(myVector.begin(), myVector.end(), 3), myVector.end()); 4. The "new fully automatic way" (since C++20): std::erase (myVector, 3); Disclaimer: I didn't compile any of the code above; some errors may/will exist :) Mircea
  • std::async

    question
    2
    0 Votes
    2 Posts
    18 Views
    L
    If you want things run in order then do not use async. See the example at std::async - cppreference.com[^].
  • C++ memory freeing

    c++ performance question
    7
    0 Votes
    7 Posts
    38 Views
    Mircea NeacsuM
    While you are absolutely right, I don't know of any heap manager that behaves the way you describe. Let's say that calling delete on an int array is a smaller sin, a "peccadillo" that will place you on one of the first circles of hell. :laugh: Mircea
  • 0 Votes
    8 Posts
    43 Views
    J
    My best practice doesn't fit either of your suggestions... If I am creating a new database layer (which I have numerous times) then the caller would never provide the SQL. If the business layer(s) need new database logic then the database layer should be modified to provide it. The caller provides the parameters that would be used in the call. Then within that database layer method it would decide how to process the parameters and SQL (provided by the method.) So it looks like the following. void DatabaseDoX(param1, param2,...) { // multiple variations possible std::string fullyFormedQuery = sprintf (SQL_X, param1, param2, ... ); There are quite a few variations on the above. For example consider the complication of a user initiated call where they might specify different 'query' terms (like data range, customer name, etc) But all still hide the SQL. Certainly there are design considerations for example your code might be coming from within the database layer (not a business call at all.) If so then I suspect that usage would actually vary depending on what the database layer was specifically doing in the code path.
  • Should this work in C++?

    csharp c++ visual-studio question
    3
    0 Votes
    3 Posts
    17 Views
    M
    mike7411 wrote: I got it from MIT's OpenCourseware. I see the MIT is still at the cutting edge of technology !! :rolleyes: CI/CD = Continuous Impediment/Continuous Despair
  • strcpy_s weirdness

    c++ question
    4
    0 Votes
    4 Posts
    27 Views
    CPalliniC
    See, for instance Array Decay In C - GeeksforGeeks[^]. "In testa che avete, Signor di Ceprano?" -- Rigoletto
  • Finding the Parent Process

    question com data-structures json help
    10
    0 Votes
    10 Posts
    41 Views
    Richard Andrew x64R
    Thanks for your responses. I wish I had a line to Mark Russinovich. I'm sure he would know. The difficult we do right away... ...the impossible takes slightly longer.
  • linker cannot find shared library...

    help question
    16
    0 Votes
    16 Posts
    52 Views
    L
    I do appreciate your comments, especially about QT. However, since my comments are not received well...let sleeping dogs sleep.. Have a swell day.
  • how to add full path #include ?

    help tutorial question
    18
    0 Votes
    18 Posts
    88 Views
    D
    Just to be clear, I'm done with this. Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak