EvilZone

Programming and Scripting => C - C++ => : 6NavI May 05, 2013, 03:53:13 PM

: I can't run codes with strings
: 6NavI 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

:
// 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;
}

: Re: I can't run codes with strings
: vezzy 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?
: Re: I can't run codes with strings
: Chef 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!
: Re: I can't run codes with strings
: Fur 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 (https://en.wikipedia.org/wiki/Indent_style)

You may want to check out this (http://sydney.edu.au/engineering/it/~scilect/tpop/handouts/Style.htm) for more on style.

Just remember that everyone has their own preferences.