Trouble with Strings
From: DJ (chopin3_at_earthlink.net)
Date: 10/25/04
- Next message: mkarja: "Re: Reading a file from a specified range"
- Previous message: DJ: "Re: Openning a file while in an object"
- Next in thread: Philip: "Re: Trouble with Strings"
- Reply: Philip: "Re: Trouble with Strings"
- Reply: DaKoadMunky: "Re: Trouble with Strings"
- Reply: John Harrison: "Re: Trouble with Strings"
- Reply: DJ: "Re: Trouble with Strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 25 Oct 2004 08:53:54 GMT
I am currently having trouble with strings. I have a private string variable
in my class and i assign a value to it in the creation function as follows.
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
class myclass{
private:
string myString;
public:
myclass();
void testString();
};
myclass::myclass()
{
myString = "Test";
cout << "Inside " << myString << "!" << endl;
}
void myclass::testString()
{
cout << "Outside " << myString << "!" << endl;
}
int main(){
myclass m();
m.testString();
return 0;
}
Output looks like this.
Inside Test!
Outside !
Why am I losing the string outside of the scope of the initial function even
though it is a class member?
Thank you for any help,
David
- Next message: mkarja: "Re: Reading a file from a specified range"
- Previous message: DJ: "Re: Openning a file while in an object"
- Next in thread: Philip: "Re: Trouble with Strings"
- Reply: Philip: "Re: Trouble with Strings"
- Reply: DaKoadMunky: "Re: Trouble with Strings"
- Reply: John Harrison: "Re: Trouble with Strings"
- Reply: DJ: "Re: Trouble with Strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|