string vs. variable

Reply

Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

string vs. variable

 
0
  #1
Nov 10th, 2008
What would be the difference between something like

int func1 = "This is my function"

and

string func = "This is my function" (sorry if syntax is off)

The only thing ive been able to find in research, is that c++ offers a specific header to handle string i/o etc...

thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: string vs. variable

 
0
  #2
Nov 10th, 2008
int is a type built right into the language, which means you don't need to link with a library to use it. string (or std::string, to be specific) is a class in the standard library that gives you a string type. Ultimately the difference is minimal, aside from the fact that the two types are used completely differently, of course. But to use std::string, you need to include <string>.

>int func1 = "This is my function"
This is a syntax error, by the way.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Re: string vs. variable

 
0
  #3
Nov 10th, 2008
lol, ok. Syntax aside =P, you say that the difference is minimal, but the two are usually used in two completly different ways. That confuses me =(. Is the main significance with using the string class the i/o functionality then? And could you possibly throw me some examples different situations when a variable is used and when a string is used?

Thanks again
-the noob
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: string vs. variable

 
1
  #4
Nov 10th, 2008
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion. What I mean is that std::string can be used as a first-class type just like int. However, because they're different types, they have different usage patterns.

>Is the main significance with using the string class the i/o functionality then?
Nope, the significance of using the string class is being able to use strings. The significance of int is that you can do integer math, which is somewhat more difficult using strings. I/O works with both, fortunately.
Last edited by Narue; Nov 10th, 2008 at 5:30 pm.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Re: string vs. variable

 
0
  #5
Nov 10th, 2008
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.

My god, i will live by these words...

Looks like i have some quesi specifics to investigate! Up Up And AWAY!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC