|
-
May 28th, 2014, 01:28 AM
#1
Thread Starter
Hyperactive Member
String Variable in C++
We can define the variable as string data type or not.
I have read by including the header file string.h, you can declare string type variable.
But my program is having errors:- UNDEFINED SYMBOL STRING
Code:
#include<iostream.h>
#include<string.h>
int main()
{
string Name;
name="sonia";
cin.get();
return 0;
}
How can we declare the string variable??
-
May 28th, 2014, 05:14 AM
#2
Re: String Variable in C++
In ansi c++ the way to write this program is
Code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string Name;
Name="sonia";
cin.get();
return 0;
If this produces compile errors then the compiler you are using is NOT ansi c++ compliant and I would strongly suggest you change the compiler you are using to one that is ansi compilant.
Note that in your code you have string Name but use name="sonia". In c++ Name and name are different variables.
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|