Solved

simple stack and string prog's

Posted on 2003-11-01
6
367 Views
Last Modified: 2010-04-02
i need to know how to work with built-in stacks and strings, i 2 progs r below with their error messages. so plz if u can tell me y they're not working:


#include <iostream.h>
#include <stack.h>

int main()
{
      stack stk;
      for(int i=0; i<5; i++)
            stk.push(i*20%6);

      while(!stk.empty())
      {
            cout<<stk.top()<<endl;
            stk.pop();
      }

      return 0;
      
}

--------------------Configuration: test - Win32 Debug--------------------
Compiling...
main.cpp
c:\c++\test\main.cpp(2) : fatal error C1083: Cannot open include file: 'stack.h': No such file or directory
Error executing cl.exe.

test.exe - 1 error(s), 0 warning(s)


----------------------------------
#include <iostream.h>
#include <string.h>

int main()
{
      string a;
      cin>>a;
      cout<<a<<endl;

      return 0;
      
}

--------------------Configuration: test - Win32 Debug--------------------
Compiling...
main.cpp
c:\c++\test\main.cpp(6) : error C2065: 'string' : undeclared identifier
c:\c++\test\main.cpp(6) : error C2146: syntax error : missing ';' before identifier 'a'
c:\c++\test\main.cpp(6) : error C2065: 'a' : undeclared identifier
Error executing cl.exe.

test.exe - 3 error(s), 0 warning(s)


0
Comment
Question by:minjiber
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9663539
>>c:\c++\test\main.cpp(2) : fatal error C1083: Cannot open include file: 'stack.h': No such file or directory
You mean #include <stack>
using std::stack;
stack<int> stk;

>>#include <string.h>
Try #include <string>
0
 
LVL 2

Author Comment

by:minjiber
ID: 9664146
thanx n_fortynine,

the stack prob worked, but the string didnt. i would appreciate it if u send me an example, simple one like inputing a string and printing it.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 9664289
>> the stack prob worked, but the string didnt.

Try including <string>. For example,

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
    string st;

    cin >> st;
    cout << st << endl;

    return 0;
}

Cheers!
Exceter
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Accepted Solution

by:
n_fortynine earned 20 total points
ID: 9664582
>> the stack prob worked, but the string didnt.
What you are missing is, like Exceter mentioned, using namespace std;
If you don't want to write that, try writing
using std::string;
or put std::string instead of string whenever you declare a string variable.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 9664870
Also, you shouldn'tbe using the .h extensions because these files are non-standard. Just use the same names without he .h part, as I did in my example.
0
 
LVL 2

Author Comment

by:minjiber
ID: 9691820
thanx guys, boths the probs worked.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question