Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
'convert' uses undefined class 'std::basic_stringstream'

Locked 'convert' uses undefined class 'std::basic_stringstream'

  • Wednesday, June 17, 2009 3:40 PM
     
     
    #include "stdafx.h"
    #include <windows.h>
    #include <math.h>
    #include <cstdlib>
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include <string.h>
    #include <WINERROR.H>
    #include <stddef.h>
    #include <stdlib.h>
    #include <wchar.h>
    #include <tchar.h>
    string drive_ID ;
    for (int i= 65; i<=90;i++ )
    {
          stringstream convert;
          convert << i;    //*error C2079: 'convert' uses undefined class 'std::basic_stringstream<_Elem,_Traits,_Alloc>'
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Alloc=std::allocator<char>
    1>        ]
    warning C4552: '<<' : operator has no effect; expected operator with side-effect
    */
          drive_ID = convert.str();  //error C2228: left of '.str' must have class/struct/union 
          drive_ID = i + ":\\"        ;  
          drive_type = GetDriveType(drive_ID);
          if (drive_type != 3) continue;
           filename = drive_ID + ":\\Program Files\\JuniorT\\254.txt" ;
         
          exist = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
                  CloseHandle(exist);
     

    i  have encount a compile error which want sb to help
    how to amend~
    thanks

All Replies

  • Wednesday, June 17, 2009 5:28 PM
     
      Has Code
    Hello ChiWing,

    I think you can avoid that stringstream and generate the drive string like this,

    for (int i= 65; i<=90;i++ )
    {
        // Generate drive string like this.
        string drive_ID( 1, i );
        drive_ID += string( ":\\");
    
        ...
    }
    


    Regards,
    Jijo.
    http://weseetips.com [^ ] Visual C++ tips and tricks. Updated daily.
    • Edited by Jijo Raj Wednesday, June 17, 2009 5:29 PM Removed TCHAR macro.
    •  
  • Wednesday, June 17, 2009 8:36 PM
     
     Answered
    To use stringstream you need this:

    #include <sstream>

    - Wayne
  • Thursday, June 18, 2009 1:31 AM
     
     
    string drive_ID( 1, i );

    does it means it is the syntax of changing the i (decimal ASCII) to related english character?

    i will use it next , when changing (decimal ASCII) to related english character..