[try Beta version]
Not logged in

 
cin and string

Sep 8, 2016 at 6:19am
Write your question here.
i want to calculate the volume of cylinder.......
it shows these error i don't know how to resolve this

C:\Users\maria\Desktop\cinstring\main.cpp|13|error: expected ';' before 'getline'|
C:\Users\maria\Desktop\cinstring\main.cpp|17|error: expected ';' before 'getline'|
C:\Users\maria\Desktop\cinstring\main.cpp|20|error: invalid operands of types 'float' and '<unresolved overloaded function type>' to binary 'operator<<'|

code\

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
string mystr;
int rad =0;
float height =0;

cout << "enter the radius :"
getline (cin,mystr);
stringstream(mystr)>> rad;

cout << "enter the height :"
getline(cin,mystr);
stringstream(mystr)>> height;

cout << 3.14*(rad)^2*height << endl;



return 0;
}























Sep 8, 2016 at 6:31am
C:\Users\maria\Desktop\cinstring\main.cpp|13|error: expected ';' before 'getline'|

Do you realize that this error tells you the line number where it detected the problem (line 13)? And looking at line 13 what is before getline()?
1
2
cout << "enter the radius :"  // Line 12.
getline (cin,mystr);  // Line 13. 



Also the caret character ('^') is not the power symbol, it is the bitwise XOR symbol.


Last edited on Sep 8, 2016 at 6:34am
Sep 8, 2016 at 6:32am
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
string mystr;
int rad =0;
float height =0;

cout << "enter the radius :"; // <--
getline (cin,mystr);
stringstream(mystr)>> rad;

cout << "enter the height :"; // <--
getline(cin,mystr);
stringstream(mystr)>> height;

cout << 3.14 * rad * rad * height << endl; // <-- 
return 0;
}
Last edited on Sep 8, 2016 at 6:33am
Sep 8, 2016 at 2:39pm
Jlb(2398) I am clear about the xor part....but still not clear about the error in line 13...😒😒😒
Sep 8, 2016 at 2:48pm
closed account (48T7M4Gy)
I didn't look at the content of the lines but getline is not appropriate.

The radius and height inputs only require cin >> rad; and cin>> height; respectively to replace lines 13,14 and 17,18
Sep 8, 2016 at 2:58pm
but still not clear about the error in line 13

Did you not see that bolded word in my post? What is before the getline() in line 13? Answer: Line 12! Now look closely at line 12. Do you see anything missing? A semicolon perhaps? Look at kemort's post that contains a copy of your code, he highlighted the problem.

Last edited on Sep 8, 2016 at 3:00pm
Sep 8, 2016 at 3:54pm
yes got it..
Topic archived. No new replies allowed.