5 Replies - 16107 Views - Last Post: 08 July 2011 - 12:46 PM Rate Topic: -----

#1 Narek Babadjanyan   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 47
  • Joined: 30-May 11

The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 11:06 AM

In C++ there's int, double, float, char etc. Bu none of these can contain strings for exmaple...
include <iostream>
using namespace std;
int main()
{
     int name; //int, char, double, float it doesn't matter, anyway I won't get the desired result
     cin >> name;
     cout << "Hello, " << name << "! Where do you want to go today?";
     return 0;
}


I input the name John Fish for example, but int gives me a number, which i don't understand, char gives me a "J", the first letter only, what to use then?

Is This A Good Question/Topic? 0
  • +

Replies To: The defect of C++ I hate most of all, how to fix it?

#2 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1749
  • View blog
  • Posts: 5,901
  • Joined: 03-August 09

Re: The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 11:11 AM

i don't understand what your talking about exactly but it appears that you want strings. there is a very nice fix for this :) std::string

include the standard header
#include <string>

declare a string
std::string name;


get the input for it
cin>>name;

output it
cout<<name;


here is a reference for using strings
Was This Post Helpful? 1
  • +
  • -

#3 Narek Babadjanyan   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 47
  • Joined: 30-May 11

Re: The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 11:13 AM

Thank you very much, but one more thing i don't ahve to write std::string (like you did) if I have include namespace std there, right?

This post has been edited by JackOfAllTrades: 08 July 2011 - 12:24 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#4 ipushmycar   User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 11:13 AM

OR
using namespace std;



That way you can pretty much use strings as if it were Java. No need to type std:: every time.
Was This Post Helpful? 1
  • +
  • -

#5 Narek Babadjanyan   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 47
  • Joined: 30-May 11

Re: The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 11:16 AM

Oh, what a mistake, I forgot it was using namespace std :(

This post has been edited by JackOfAllTrades: 08 July 2011 - 12:26 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#6 Bench   User is offline

  • D.I.C Lover
  • member icon

Reputation: 945
  • View blog
  • Posts: 2,464
  • Joined: 20-August 07

Re: The defect of C++ I hate most of all, how to fix it?

Posted 08 July 2011 - 12:46 PM

I created a thread on here a while ago which discusses the basics of strings in C++:
http://www.dreaminco...2209-c-strings/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1