How can i use sstream in MFC

This is a discussion on How can i use sstream in MFC within the C++ Programming forums, part of the General Programming Boards category; I tried to use istringstream function in MFC to convert CString to Int, but failed ..... Code: CString cisbn; int ...

  1. #1
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149

    How can i use sstream in MFC

    I tried to use istringstream function in MFC to convert CString to Int, but failed .....

    Code:
    CString cisbn;
    int l;
    .........
    ..........
    istringstream temp(cisbn.substr(12,1));
    temp>>l;
    i got this error message:
    E:\Temporary\mfc\b\bDoc.cpp(158) : error C2065: 'istringstream' : undeclared identifier
    E:\Temporary\mfc\b\bDoc.cpp(158) : error C2146: syntax error : missing ';' before identifier 'temp'
    E:\Temporary\mfc\b\bDoc.cpp(158) : error C2065: 'temp' : undeclared identifier

    any help would be greatly appreciated!

    blow me ... ...

  2. #2
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    I am pretty sure you can include header files in MFC. For instance:
    Code:
    #include <sstream> // Include istringstream header
    using namespace std;
    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Maybe... std::istringstream instead? Don't know what your header situation looks like (did you take into account the namespace issue in some fashion) so that's just a guess.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    yes
    i have already added the header
    #include<sstream>
    using namespace std;

    is there any way else to convert CString to int?

    blow me ... ...

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

  6. #6
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    There are a few ways to convert a CString to an integer. Fordy provided a good link. The main idea is to use the *toi or *toul functions. For further reference to CString conversion, view the following links:
    If you are curious about ttoi() or other functions used in the previous link, you can always view this guide on Language Portable Code. Just do a search for the function names, i.e., ttoi().


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  2. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  3. Understanding The Future of MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-15-2002, 09:08 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 05:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 12:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21