Small string problem VS2010Express

Hi. I'm new to C++ and programming in general. I'm in the process of working my way through the C++ Language Tutorial from this site and have run into a pesky but seemingly simple problem. My code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//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 Amount:";
	getline (cin,mystr);
	stringstream(mystr);
	cout<<"Total Price:"<< price*quantity << endl;
	return 0;
}

I get these two errors: error C2371: 'mystr' : redefinition; different basic types and see declaration of 'mystr'. I'm using Visual Studio 2010 Express and it's a win 32console app empty project. Any help is greatly appreciated. Thanks for your time and please excuse any forum etiquette I may have offended as I am new to the forums as well. Thanks again.
#include "stdafx.h" should be included for VS. I know, it's annoying.
Last edited on
Thank you for the reply. I included #include "stdafx.h" and received this error: 'stdafx.h': No such file or directory. Any ideas?
You forgot to convert the quantity with the second stringstream.

stringstream(mystr);

should be

stringstream(mystr) >> quantity;

Moonraker wrote:
#include "stdafx.h" should be included for VS.

Not if you create an empty project or turn off pre-compiled headers.
Yep that fixed it. :) Thank you for your quick replies. Greatly appreciated.
Topic archived. No new replies allowed.