SStream Problem

Hi all.

I was making the tutorial code for sstream, using Dev-C++ 4. This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream.h>
#include <stdlib.h>
#include <sstream>
#include <string>

using namespace std;

int main()
{
      string mystr;
      float price = 0;
      int quantity = 0;

      cout << "Enter price: ";
      getline(cin,mystr);
      stringstream(mystr) >> price;
      cout << "Enter Quaintity: ";
      getline(cin,mystr);
      stringstream(mystr) >> quatity;
      cout << "Total price: " << price*quantity << endl;
      system("PAUSE");
}


And this was the error:
3 c:\codes\c__~1\c__pro~1\sstrea~1.cpp
sstream: No such file or directory

Someone know why this would happen?
iostream.h is deprecated. Use iostream.
sstream is not a C++ header. Use stringstream.
This problem happens often enought that it is easy to mix it up. <sstream> is the proper header, but your compiler and/or libraries are pre-standard C++.

You ought to update your MinGW to the latest stable version and you'll be able to get going just fine.
http://sourceforge.net/project/showfiles.php?group_id=2435
I recommend just getting the GCC version 4. While it is still alpha and has a few bugs, it is still very stable. I use it all the time without problems.
Huh. You're right. I misread the reference.
I updated MinGW, but it still not work :/ So, I downloaded Codes Block, and now, it gives me this error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
      string mystr;
      float price = 0;
      int quantity = 0;

      cout << "Enter price: ";
      getline(cin,mystr);
      stringstream(mystr) >> price;
      cout << "Enter Quaintity: ";
      getline(cin,mystr);
      stringstream(mystr) >> quatity;
      cout << "Total price: " << price*quantity << endl;
      cin.get();
}


C:\Codes\C++\C++ Projects\sstreamCin.cpp||In function `int main()':|
C:\Codes\C++\C++ Projects\sstreamCin.cpp|18|error: `quatity' was not declared in this scope|

I did looked if was some sintax error, ect., looked the tutorial searching for some error I could made, but I diden't find anything :/ Help is appreciated...

And Duoas, thanks for the help, and about the GCC... I not liked it too much because it is text only...

EDIT: >.<"""" I saw the problem...
Last edited on
Topic archived. No new replies allowed.