Error sstream no such file or directory

  • Forum
  • Beginners
  • SStream Problem

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:codesc__~1c__pro~1sstrea~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:CodesC++C++ ProjectssstreamCin.cpp||In function `int main()’:|
C:CodesC++C++ ProjectssstreamCin.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.

graphics.h is used for drawing graphics in c language. You can draw the different shapes, graphs, or write your name using this library in c language. This library is pretty cool. But questions come in our mind that how to include graphics.h library in our CodeBlocks software and can start drawing amazing graphics. So let’s move towards the answer on how to include graphics.h in CodeBlocks…

Note: New Codeblocks version(20.03 or later) that comes with the MinGW compiler doesn’t work. If you have already installed codeblocks with the MinGW version then please uninstall it and reinstall the codeblocks setup and MinGW compiler separately. Here are the links for codeblocks and the MinGW.

Codeblocks: http://www.codeblocks.org/downloads/26 (select only setup file, e.g. “codeblocks-20.03-setup.exe”)

MinGW: https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe (After Installation add the path to the Environment variable. The path will be “C:MinGWbin”)

step 1

Download WinBGIm from http://winbgim.codecutter.org/ or use this link.

step 2

Extract the downloaded file. You’ll get three files:

  • graphics.h
  • winbgim.h
  • libbgi.a

step 3

Copy and paste graphics.h and winbgim.h files into the include folder of your compiler directory. (If you have MinGW installed in C drive of your computer, go through Disk C >> MinGW >> include. Paste these two files there.)

step 4

Copy and paste libbgi.a to the lib folder of your compiler directory. (If you have MinGW installed in C drive of your computer, go through Disk C >> MinGW >> lib. Paste these one files there.)

step 5

Open Code::Blocks. Go to Settings >> Compiler >> Linker settings.

step 6

In that window, click the Add button under the “Link libraries” part, and browse and select the libbgi.a file copied to the lib folder in step 4.

step 7

Go to “Other linker options” on the right part and paste these commands:

-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

step 8

Make sure you got steps 6 and 7 right! Here’s a screenshot of the previous two steps. Then, click Ok.

compiler settings

step 9

If you now try compiling a graphics.h program code in C or C++, you’ll still get error. To solve it, open graphics.h file (pasted in include folder in step 3) with Notepad++. Go to line number 302, and replace that line with this line:

int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,

graphics in codeblocks3

Save the file. Done!

Now you can compile any C or C++ program containing graphics.h header file. If you compile C codes, you’ll still get an error saying: “fatal error: sstream : no such file directory”. For this issue, if your file extension is .c, change it to .cpp.

[If still it is not giving an output then use this link and download ‘libbgi.zip’ file then extract it. you are getting “libbgi.a” file. Copy and paste libbgi.a to the lib folder of your compiler directory.(If you have CodeBlocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> MinGW >> lib. Paste these one files there.) now your program will work.]


How to setup winBGIm / graphics library in Code Blocks


Note:
I have answered few FAQs in the Internet regarding this topic at the very end of this blog. Go through those if you have already tried main explanation.


Things everybody skip: Those who think, TurboC is too old to use these days and wanna upgrade to other cool compilers like, Microsoft Visual Studio(best one so far), Code::Blocks, Dev C++ or any other. It’s a good thing to do.

I have used MicroSoft Visual Studio, Code::Blocks and Dev C++ for few years now and I find Code::Blocks to be the better one next to Visual Studio. Dev C++ is good in some ways but Code::Blocks gets better and better with each updates. So, I recommend Code::Blocks over Dev C++.

Alright, let’s get to the point, I was trying few graphic coding the other day in TC(Yeah, I still use it sometimes; Because, it’s kinda home for us, 90’s kids) because I was bored to configure Code::Blocks to graphics. Until now. So , I started my journey to find ‘ways’ to setup graphic coding in code::blocks. It took few hours. It was pain in the ass. I am writing this blog to save that pain for ya! Hey, Imma good guy, alright!

I think, there are three kinds of people in this world:

* Those who program.

* Those who try/tried programming and

* Lame.

Alright, let’s get to the point.. really..

Now, those who are trying to use graphics.h in Code::Blocks, ATTENTION!

So, how to include graphics.h in Code::Blocks? If you’ve tried downloading graphics.h header file and pasting it in the include directory, but yet it’s showed/showing error, blablabla… here’s a step-by-step solution! You know it or not, there are few settings Code::Blocks wants you to make, to successfully run or execute C/C++ graphic programs.

Stuff to read: To setup graphics in Code::Blocks, you’ll first have to set up winBGIm library(download graphics.h). WinBGIm is a graphics library ported to computer by Michael Main(Thanks man!) at the University of Colorado(I hope, I spelled it correctly). It emulates graphics for the MingW(GCC port) compiler. Like the TC++ IDE, the BGI(Borland Graphics Interface), is old; But not outdated, yet. It is still used in many C/C++ programs in schools and colleges.

Hmm, even though you can find many alternatives to winBGIm library, it is good for beginners in programming field. WinBGIm is the easiest graphic library you can find-Yeah!


Steps to include graphics.h in Code::Blocks:

Note: Last step is very important.



Step 1: Download of Code::Blocks v16(latest) and install it. This step is NOT necessary. It’s just good thing to be up to date to avoid bugs. You can skip this step, if you are fine with whatever version you have. LINK. Size: 78.6MB

Step 2: Now, download winBGIm.rar(It’s actually same link as above). Size: 24KB

Note: That link also contains Test codes, so that you can test whether your setup is working or not. And also, ScreenShots of settings to make inside CodeBlocks.

Step 3: Extract(of course) and you’ll get these files:

  • graphics.h
  • winbgim.h
  • linker_code.txt
  • libbgi.a

Step 4: Copy and paste graphics.h and winbgim.h files into the include folder of your compiler directory.

If you have Code::Blocks installed in C drive of your computer, go through:

Drive C > Program files or Program files(x86) > CodeBlocks > MinGW > include

Step 5: Copy and paste libbgi.a to the lib folder of your compiler directory. Same path as above.

Step 6: Now, open Code::Blocks. Go to Settings > Compiler > Linker settings

Step 7: In that window, click the Add button under the «Link libraries» part, and browse and select the libbgi.a file copied to the lib folder in Step 5.

Step 8: Go to «Other linker option» on the right part of same window and paste these commands or use linker_code.txt file:

    -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Step 9: Make sure you got Steps 7 and 8 right!

Step 10: Say out loud: Yay! We did it!

Edit: I have deleted old comments and answered common questions below in FAQ section. If you have any questions, bring them up in the comments section. Also, now that the post is revised and updated, leave a feedback in the comments, if the aforementioned procedure to include graphics.h in CodeBlocks worked out for you.

___________________________________________________________________________________

Here are some frequently asked questions answered:

Question 1: Hey Tejas, I have completed all above steps carefully but I am still getting following error while building program with graphics.h header:

fatal error: sstream : no such file directory

What should I do now?

Answer: This is probably because you have file extension .c; Change it to .cpp

Reason is, there is no library sstream in C. It’s in CPP. Since graphics.h uses sstream, you have to code all graphic programs with .cpp extension. No big deal. Cheers!

Question 2: Some people in Internet suggested me to edit graphics.h‘s 302nd line from int right=0 to int top=0; But still I have errors. What to do?

Answer: This is probably because, you are using ‘bad’ library files. Go to Step 3 and download ‘bug fixed‘ library files. Replace previous files with new(downloded) ones following above steps. You don’t have to link again, though. Just check commands in Step 8 once. And you can celebrate! 

Question 3: Thanks for the detailed tutorial. After doing all the necessary steps, my program builds without error. But, when I run it, my console window crashes with error 

filename.exe has stopped working.

Also message displayed is process returned (0xFF). Kindly help me with what could be the reason of this.

Answer: You’re welcome. Again this is because of ‘bad’ library files. Note that, process is returning a very big number. So, this is runtime error. Refer to Question#2 and it’s answer.

Понравилась статья? Поделить с друзьями:
  • Error ssl version or cipher mismatch chrome
  • Error ssl protocol error chromium gost
  • Error ssl protocol error bitrix
  • Error ssl peer certificate or ssh remote key was not ok insomnia
  • Error ssl intermediate chain is not valid