I am using visual studios 2010 if that means anything. fatal error C1083: Cannot
ID: 3639591 • Letter: I
Question
I am using visual studios 2010 if that means anything.
fatal error C1083: Cannot open include file: '"Stack.h"': Invalid argument
Don't know if I called the header file wrong or what the problem is. but it's the only error message I get.
under Stack_test.cpp.
The #include <"Stack.h"> has a red line under the #include (cannot open source file "Stack.h")
which is why the main has the error. Plus a few other items not recognized within the main that undefined.
in my Stack.h. there are no errors.
Here is the code:
//main
// Stack_test.cpp
#include <string>
#include <iostream>
#include <cassert>
#include <"Stack.h">
#include <list>
#include <vector>
using namespace std;
int main()
{
Stack<int, Vector> s1;
assert(s1.size() == 0);
assert(s1.empty());
s1.push(16);
assert(s1.size() == 1);
assert(s1.top() == 16);
s1.pop();
assert(s1.size() == 0);
s1.push(11);
assert(s1.size() == 1);
assert(s1.top() == 11);
s1.push(22);
assert(s1.size() == 2);
assert(s1.top() == 22);
s1.push(33);
assert(s1.size() == 3);
assert(s1.top() == 33);
s1.pop();
assert(s1.size() == 2);
assert(s1.top() == 22);
Stack<String, List> s2;
s2.push("abc");
s2.push("de");
s2.pop();
assert(s2.top() == "abc");
cout << "SUCCESS ";
};
//header file
#ifndef STACK_H
#define STACK_H
#include <cassert>
#include <cstdlib>
#include <vector>
#include <list>
#include <string>
#include <iostream>
using namespace std;
template <class T, template <class T, class = allocator<T> > class Container = list>
template <class T, template <class T, class = allocator<T> > class Container = vector>
template <class T, template <class T, class = allocator<T> > class Container = string>
class Stack
{
public:
Stack(); container() {}
Stack() {~container(); }
bool empty() const { return container.empty(); }
unsigned int size() const { return container.size(); }
void push( const T & x) { return container.push_back(x);}
void pop() { return container.pop_back();}
T & top() {return container.back();}
private:
Container<T> container;
};
#endif
Explanation / Answer
In your Stack.cpp file, change #include to #include "Stack.h" Also make sure that you have your Stack class in a file called Stack.h and another file called Stack.cpp which implements all of the Stack class's functions.Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.