string in STL

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

string in STL

Post by asif_rahman0 »

I am facing a trouble for STRING in STL.

Code: Select all

#include <string>
#include <cstdio>
using namespace std;
......
string name;
...........
int main(){ scanf("%s",name); return 0;}
....
Why does it cause problem?? Can anybody tell me?
But

Code: Select all

...
cin>>name;
..
It works fine.
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

because scanf wants to see the name as a simple char* ! and it is not possible.
read a string with cin or getline instead of scanf
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post by asif_rahman0 »

thnx.
Post Reply

Return to “C++”