memory address

This is a discussion on memory address within the C++ Programming forums, part of the General Programming Boards category; I'm doing tests on a class I'm writing to deal with Carbon data field IO My methods work perfectly to ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    memory address

    I'm doing tests on a class I'm writing to deal with Carbon data field IO

    My methods work perfectly to get the data as a CFStringRef

    I then decided to write the method to get the data as a string.

    in order to do this, I used the following code:

    Code:
    ostringstream strstrBuffer;
    
    strstrBuffer<<getCFStringFieldData()<<flush;
    
    return strstrBuffer.str();
    this compiles, and the method calls were executed

    I then needed to test that they were returning the right thing.

    so I declared a string (test), set its value as getDataAsCppString() and executed a cout statement: cout<<test<<"\n";

    the program ran and the memory address of test was printed out

    how do I get the actual string to print out?

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    I think you need to post more code if you want further help!
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    This is the source for the whole header file

    Code:
    /*
     *  carbonGraphicIO.h
     *  
     *
     *  Created by Erik Schmidt on 3/25/05.
     *  Copyright 2005 Erik_Soft. All rights reserved.
     *
     *  Provides eased IO capability within data fields in a carbon application
     *
     *  C++ version
     *
     */
    
    #include <Carbon/Carbon.h>
    #include <sstream>
    #include <string>
    #include <cstring>
    
    using namespace std;
    
    class DataField {
    private:
    
    	ControlID contID;
    	CFStringRef cfbuffer;
    	ostringstream strstrBuffer;
    	WindowRef window;
    	ControlHandle conthan;
    	Size actualSize;
    	
    public:
    
    	//class Constructor
    	DataField(ControlID commid,WindowRef win){
    	
    		contID=commid;
    		
    		window=win;
    		
    	}//end DataField
    	
    	//Gets a CFString from the data field, takes no arguments, returns a CFStringRef
    	CFStringRef getCFStringData(){
    	
    		GetControlByID(window,&contID,&conthan);
    		
    		GetControlData(conthan,0,kControlEditTextCFStringTag,sizeof(CFStringRef),&cfbuffer,&actualSize);
    		
    		return cfbuffer;
    		
    	}//end getCFStringData
    	
    	//Gets a c++ string from the data field, takes no arguments, returns a c++ string
    	string getCppStringData(){
    	
    		cfbuffer=getCFStringData();
    		
    		strstrBuffer<<cfbuffer<<flush;
    		
    		return strstrBuffer.str();
    		
    	}//end getCppStringData
    	
    };//end class DataField

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    c'mon, someone has to know what the problem might be!

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    cout<<test<<"\n";
    the program ran and the memory address of test was printed out

    Just off the top of me' head, try dereferrencing 'test' and see what happens:
    Code:
     cout << *test << "\n";


    [edit] is 'test' a string or cstring??
    Last edited by The Brain; 03-29-2005 at 09:17 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 12:41 PM
  2. Pointer to specific memory address
    By elnerdo in forum C++ Programming
    Replies: 10
    Last Post: 05-19-2006, 08:35 AM
  3. Memory Address
    By Stack Overflow in forum C Programming
    Replies: 5
    Last Post: 05-25-2004, 12:43 PM
  4. Memory address?
    By Munkey01 in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 09:04 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 10:37 AM

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