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
  • Reading the Whole Array of Data from JSON

    c++ data-structures json help question
    7
    0 Votes
    7 Posts
    1 Views
    L
    Hi I modified the program but still not able to get the whole array of data Under Items. Below is the sample code. Please let me know where it is wrong. namespace pt=boost::property_tree; pt::ptree root; pt::ptree items; pt::ptree obsrvtns; pt::ptree obsrvtns1; pt::read_json(filepath,root); obsrvtns=root.get_child("Header"); cout<<"Header size is "<first<<": "<second.get_value()<<"\n"; } items=root.get_child("Serial"); cout<<"Series Size is "<second.size()<<"\n"; for(boost::property_tree::ptree::iterator it1=it->second.begin();it1!=it->second.end();++it1) { cout<first<<": "<second.get_value()<<"\n"; if(it1->first=="Item") { /*obsrvtns1=it1->second.get_child("Items"); cout<<"check \n";*/ //BOOST_FOREACH(boost::property_tree::ptree::value_type &v,root.get_child("Header.Serial.Item")) BOOST_FOREACH(boost::property_tree::ptree::value_type &v,root.get_child("Item")) { cout<
  • MFC: Most recently used (MRU) files

    c++ tutorial architecture help question
    4
    0 Votes
    4 Posts
    0 Views
    V
    You are welcome! :) :)
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    14 Posts
    0 Views
    M
    Excellent, Thanks
  • having problem to find an error

    help question com algorithms
    5
    0 Votes
    5 Posts
    0 Views
    P
    In addition to other answers. Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes. #include using namespace std; int main() { int t; cin>>t; std::string s[t]; for(int i=0;i<=t-1;i++) { string st; getline(cin,st); int l=(int)st.length(); string s2="",s3=""; for(int i=0;i<=l;i++) { if(st[i]==' '||st[i]=='\0') { s3=s2+" "+s3; s2.clear(); } else { s2+=st[i]; } } s[i]=s3; } for(int i=0;i<=t-1;i++) cout< Indentation style - Wikipedia[^] Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting. Notepad++ Home[^] ultraedit[^] Enabling Open Innovation & Collaboration | The Eclipse Foundation[^] Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein
  • std:strstream does not work

    c++ ios
    12
    0 Votes
    12 Posts
    16 Views
    L
    I think your original idea in your first post... std::stringstream was probably the best way. You just needed to add a istream operator >> to handle the CComponent. Something like this: class CComponent { private: std::string something; public: CComponent() noexcept = default; friend std::istream& operator >> (std::istream& in, CComponent& component); }; istream& operator >> (istream& in, CComponent& c) { in >> component.something; return in; } Which could then be used like this: const std::string test_haakon = "Lorem ipsum dolor sit amet"; CComponent test_component; std::stringstream test_string_stream(test_haakon.c_str()); test_string_stream >> test_component; Merry Christmas to you and your family. Best Wishes, -David Delaune UPDATE: I really hate answering these modern C++ questions because it takes a lot more effort. I shouldn't have said that it was 'probably the best way' because if you use the code above it will make a copy of the data three times. If you are able to use C++17 in your project then you will be able to avoid one of those copies by deriving a class from std::basic_streambuf as such: class CComponent { private: std::string something; public: CComponent() noexcept = default; friend std::istream& operator >> (std::istream& in, CComponent& component); }; template > class make_stream_buffer_no_copy : public std::basic_streambuf { public: make_stream_buffer_no_copy(CHAR* p, size_t len) { basic_streambuf::setg(p, p, p + len); basic_streambuf::setp(p, p + len); } std::basic\_stringstream get\_stream() { return std::basic\_stringstream(basic\_streambuf::pbase(), ios\_base::in | ios\_base::out); } }; istream& operator >> (istream& in, CComponent& c) { in >> c.something; return in; } Which you would use like this: CHAR p2[] = "Lorem ipsum dolor sit amet"; CComponent test_component2; make_stream_buffer_no_copy no_copy(p2,strlen(p2)); no_copy.get_stream() >> test_component2; You can avoid ALL copying if you are willing to extend your CComponent class.
  • gdi+ bitmap save on existing file - showing error

    graphics help winforms
    3
    0 Votes
    3 Posts
    0 Views
    G
    Thank you Richard. This helps me to solve my issue. Regards, Gopi.
  • Configure Script Issue

    security tools help tutorial question
    3
    0 Votes
    3 Posts
    0 Views
    K
    You don't say whether make completes successfully or not. The compiler flags given tell the compiler where to find the pieces to buld the program. If the compile has completed successfully, but when you try to run the program you get a message "error while loading shared libraries: <libname.so>: cannot open shared object file: No such file or directory then the problem is at runtime, not compile time. As Randor notes, you can tell the link-loader where to find the library with LD_LIBRARY_PATH k5054@localhost$ LD_LIBRARY_PATH=/usr/local/lib64 myprog arg1 arg2 sets LD_LIBRARY_PATH for the given command. To set for a single session do k5054@localhost$ export LD_LIBRARY_PATH=/usr/local/lib64 k5054@localhost$ myprog arg1 arg2 You can add that to your shell's .profile file. and it will be set every time you log in. If you want to set this up permanently for all users ont the system, then as root create a file /etc/ld.so.conf.d/local.conf containing the single line /usr/local/lib64 Now, as root, run ldconfig, and you should be able to run your program from any login, without needing to set LD_LIBRARY_PATH in your .profile or per session/per command. you can check what libraries are being loaded using the ldd command < k5054@localhost$ ldd /bin/bash linux-vdso.so.1 (0x00007ffebf5f6000) libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f7ec6539000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7ec6533000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ec6341000) /lib64/ld-linux-x86-64.so.2 (0x00007f7ec66b5000) If the link-loader can't find a library, it will show libsomelib.so => not found Keep Calm and Carry On
  • 0 Votes
    3 Posts
    0 Views
    L
    Your Shape class should be the only abstract one. Circle and Rectangle should be complete classes that inherit Shape. There is a very good set of articles on factory patterns by @SneshPrajapati here on CodeProject, starting with Factory Patterns - Simple Factory Pattern[^].
  • Beginning C++ for Windows Application

    question c++ json learning workspace
    3
    0 Votes
    3 Posts
    0 Views
    L
    It depends on what you are trying to learn. If you know C++ then Win32 should be fairly easy. But if you do not know C++ then that is what you need to start with. Here is a starter for C++: Learn C++[^] And one for Windows: EFNet #Winprog[^]
  • Your Saudi Arabia Email List Subject Lines

    help business sales code-review
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • cmath.h compile error

    c++ help
    14
    0 Votes
    14 Posts
    0 Views
    H
    I honestly don't know what is going on. Some files had #include . Removing this did't help. It reported error in cmath anyway. When googling "cmath error c2062" I see that others have had the same problem. Anyway, it seems that I have found the solution.
  • C++ class question

    question c++
    18
    0 Votes
    18 Posts
    0 Views
    pkfoxP
    :-D "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
  • Netserverenum function return false detail

    sysadmin java
    10
    0 Votes
    10 Posts
    0 Views
    U
    Hi David, thanks for the updates.
  • DROPEFFECT_NONE does not work in conjunction with CF_HDROP

    help
    3
    0 Votes
    3 Posts
    0 Views
    M
    The target window (CTreeCtrl) is returning on the OnDragEnter and OnDragOver a DROPEFFECT_NONE. The cursor is displaying as if I returned a DROPEFFECT_COPY. I can return back other types like DROPEFFECT_MOVE or DROPEFFECT_LINK and those behave properly. The interesting thing is that OnDrop is not called if I do return DROPEFFECT_NONE, and it is called in the case I do DROPEFFECT_MOVE, etc. So the function calling is correct. It is only the cursor that is being displayed that is not correct. Also in this same application within other windows, I am using other implementations (different window types) of COLEDropTarget and the cursor behavior is correct. I have no clue where else to look at this time. As a workaround, I'm using the CImageList Drag concept to display a NOT symbol beside the cursor when DROPEFECT is NONE.
  • Why can't I print my watermark in chrome and edge?

    question adobe help tutorial
    3
    0 Votes
    3 Posts
    0 Views
    L
    Hi, Some thoughts: 1.) Chrome (and Microsoft Edge based on Chromium) rendering process set the PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY[^] which will block Win32k in the rendering process. But this probably is not causing your issue. 2.) The Chrome (and Microsoft Edge based on Chromium) top/root process sets the PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY[^] which will block AppInit and other types of extension points. This is probably causing your hooking DLL to not load. You should probably look for other solutions. Best Wishes, -David Delaune
  • EDITED Using template in C++ - run time error

    c++ database wpf design debugging
    30
    0 Votes
    30 Posts
    1 Views
    L
    What does this have to do with the problem? You were asked to create a sample that demonstrates the problem you are having. This merely demonstrates that correct management of the index variable makes the code work.
  • to bool or not to bool?

    c++ question
    5
    0 Votes
    5 Posts
    0 Views
    D
    Given that the bool type has existed in C from its earliest days, don't you think that if the result of a method is Boolean (true / false), you should treat it as such in code? bool isFoo(); void bar() { if (isFoo()) { // do something } else { // do something else } } Even C has had a built-in _Bool type (define bool, true, and false by including stdbool.h) for 21 years! Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
  • I can't compile and put it as a variable and matrix

    help
    10
    0 Votes
    10 Posts
    0 Views
    J
    If you want to save the value into an array, you have to say which array and whereabouts in the array you want it to go. My guess is that you want something like scanf("%d", &item[i][j]); [Caveat Emptor: It is several decades since I wrote C programs, so my syntax may be awry]
  • Gomoku in C++

    c++ game-dev question lounge
    2
    0 Votes
    2 Posts
    0 Views
    Greg UtasG
    You need to learn how to use a debugger to find your problem. It will allow you to step through your code, one line at a time, to find out where it's doing something unexpected. I will point out, however, that you can map a char to a range that starts at 0 like this: t = eng - 'A'; 'A' through 'Z' have contiguous values, so this maps eng to 0 to 25, assuming that it was an uppercase letter. You can check for invalid input with if((t < 0) || (t > 14))... // or t > ('O' - 'A') Similarly, you can write cout << ' ' << i + 'A'; Robust Services Core | Software Techniques for Lemmings | Articles The fox knows many things, but the hedgehog knows one big thing.