minjiber
asked on
simple stack and string prog's
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;
}
--------------------Config uration: 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;
}
--------------------Config uration: 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)
#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;
}
--------------------Config
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;
}
--------------------Config
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)
ASKER
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.
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.
>> 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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
thanx guys, boths the probs worked.
You mean #include <stack>
using std::stack;
stack<int> stk;
>>#include <string.h>
Try #include <string>