Loading
submit to reddit
May 25, 2013, 01:49:49 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: [SOLVED]Name reading  (Read 1065 times)
taigi100
Newbie
*
Posts: 19


« on: August 04, 2010, 02:20:54 PM »

Hey guys,i need a bit of help in borland C++
i have problems reading a name if i dont know how many character the name has i tryed something like this but it didnt work Sad:
cout<<"plz insert ur name here:";
while(f==0){
cin>>a[t];
t++;
if(a[t]==NULL){
f=1;}}
cout<<"Hello ";
for(q=1;q<=t;q++)
cout<<a[q];
cout<<" be ready to start the game";
but it didnt work out i mean it was reading character till the infinit
then i saw smt with :
sting name;
cin>>name;
cout<<name;
but it seems like the declaration in borland and visual c++ is not the same at variabiles... could someone give me an ideea or the code plz?(in the last example i used sting.h)
« Last Edit: August 05, 2010, 06:26:22 AM by taigi100 » Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 903



« Reply #1 on: August 04, 2010, 02:50:25 PM »

Use an STL string, they're resizable. You can watch this to see examples of how to use them.

http://xoax.net/comp/cpp/console/Lesson46.php

Mike
Logged
taigi100
Newbie
*
Posts: 19


« Reply #2 on: August 04, 2010, 02:54:58 PM »

hmm i saw that declaration string qName; saddly that dosent work in borland it sais : Undefinited simbol 'string'
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 903



« Reply #3 on: August 04, 2010, 11:13:13 PM »

Unless your compiler is extremely old, it should have the string class. You need to be sure to use the include statement and namespace qualifier as we showed. If your compiler is too old, I'd recommend Microsoft's. They are the most active in the development of their compiler and IDE. You can install it and use it for free, as we demonstrated in our lesson 0 video.

Mike
« Last Edit: August 04, 2010, 11:14:45 PM by Michael Hall » Logged
taigi100
Newbie
*
Posts: 19


« Reply #4 on: August 05, 2010, 05:39:38 AM »

yea but the problem is that im 14 and at olimpics i have to use borland not dev mingw i will start using ming in the 9th grade but 1 year left till that
Logged
taigi100
Newbie
*
Posts: 19


« Reply #5 on: August 05, 2010, 06:25:33 AM »

NVM SOLVED
i used a bit of c
char name[20];
scanf("%s", &a);
for the cin part and for the cout one
while(f==0){
cout<<a[v];
v++;
if(a[v]==NULL)
f=1;
}
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 903



« Reply #6 on: August 05, 2010, 07:56:45 AM »

Great! I didn't know truncation was an option for you. You can also use cin.getline() to as we did in lesson 44.

http://xoax.net/comp/cpp/console/Lesson44.php

That will truncate the string just like scanf() and it's a C++ function, if you're partial to that.

Mike
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!