Author Topic: I can't run codes with strings  (Read 1451 times)

0 Members and 1 Guest are viewing this topic.

Offline 6NavI

  • /dev/null
  • *
  • Posts: 17
  • Cookies: -3
    • View Profile
I can't run codes with strings
« on: May 05, 2013, 03:53:13 pm »
Hey EZ
every time i try to run a codes with strings in them i get the notification that the program has stopped working can some pliz help me to rectify this am using CODEBLOCKS
Even this code won't run am not saying am the one who wrote it but am just using it as an example

Code: [Select]
// stringstreams
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string mystr;
float price=0;
int quantity=0;
cout << "Enter price: ";
getline (cin,mystr);
stringstream(mystr) >> price;
cout << "Enter quantity: ";
getline (cin,mystr);
stringstream(mystr) >> quantity;
cout << "Total price: " << price*quantity <<
endl;
return 0;
}

« Last Edit: May 05, 2013, 03:53:44 pm by 6NavI »
****6NavI****

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: I can't run codes with strings
« Reply #1 on: May 05, 2013, 06:50:57 pm »
Although the code is sloppy and lacks indentation, I successfully compiled it with g++ and it functions as it should on my end. Scratch the IDE and try it yourself?
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Chef

  • Peasant
  • *
  • Posts: 126
  • Cookies: 3
  • Corrupted Soul
    • View Profile
Re: I can't run codes with strings
« Reply #2 on: June 22, 2013, 08:26:34 pm »
Although the code is sloppy and lacks indentation, I successfully compiled it with g++ and it functions as it should on my end. Scratch the IDE and try it yourself?

Explain indentation to me? So far my codes are looking nice and easy to read but I don't wanna end up sloppy!
"To find happiness is to not always laugh."

Offline Fur

  • Knight
  • **
  • Posts: 216
  • Cookies: 34
    • View Profile
Re: I can't run codes with strings
« Reply #3 on: June 22, 2013, 08:57:07 pm »
Explain indentation to me? So far my codes are looking nice and easy to read but I don't wanna end up sloppy!
Indent Style

You may want to check out this for more on style.

Just remember that everyone has their own preferences.
« Last Edit: June 22, 2013, 09:03:57 pm by Fur »