![]() |
|
#1
|
|||
|
|||
strings and referencingI'm using the string library and I thought that because strings were passed by reference that I didn't need pointers. Right now the program isn't sending anything to standard output like it should be.
CPP / C++ / C Code:
Last edited by LuciWiz : 04-Jul-2005 at 23:39.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
||||
|
||||
|
First off, you will be more likely to get help by reading the how to post requests thread which will tell you how to use code tags. It gives some good pointers on including information as well.
Quote:
Your problem is that you are not passing by reference you are passing by value. When s ends up in your test routine it sets the local variable s to "asdfadfs". The variable s in main is a different variable of the same name (with different scope if you will) and never gets set to anything. Now, as you will see I will put the code between the code tags. Code:
CPP / C++ / C Code:
In order to charnge this change your function just a bit. CPP / C++ / C Code:
Now you will be operating on the s from main when you are in test(). Is there a reason for all the excess in your includes? For your simple example you just need the following. CPP / C++ / C Code:
As you see, I commented out the using namespace std; and just used the using std::cout and string. They accomplish the same end result but are more limiting in what they actually include. There are quite a few posts that a search of the forum can dig up. If you don't like my method you could just go back to the using namespace std way and get rid of the using statement. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
|
I should I be using the string library or should I be using character arrays? Is one faster than the other? Also, I put in the code you suggested and got the same result.
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
|
Quote:
Quote:
CPP / C++ / C Code:
Header Files http://msdn.microsoft.com/library/de...eaders_stl.asp <string> http://msdn.microsoft.com/library/de...ing_header.asp is not the same as <cstring> http://msdn.microsoft.com/library/de...ing_header.asp |
Recent GIDBlog
Prepping for deployment by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The