| | |
string vs. variable
![]() |
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.
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.
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
Thanks again
-the noob
>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.
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.
Last edited by Narue; Nov 10th, 2008 at 5:30 pm.
I'm here to prove you wrong.
![]() |
Similar Threads
- Parse a concatenated variable and string? (PHP)
- value of a variable whoose name is in another string variable... (Java)
- setting a string as a variable name (Python)
- Convert string variable into form object in VB6 (Visual Basic 4 / 5 / 6)
- Need help passing database column value to a string variable. (ASP.NET)
- Search for a string in a variable--- (PHP)
- Problem with string variable in void prnt function (C++)
- "String class" (Java)
Other Threads in the C++ Forum
- Previous Thread: Rock paper scissors using functions
- Next Thread: wont let me create a vector of my user defined class
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output pointer problem program programming project python random read recursion reference rpg shutdown() std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






