using namespace std bug (.cpp accessing .h files)

My .cpp file shows me a bug, and it says a nested namespace should be used, but I don't understand why and how.

Here is the error message and the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// Error message



mingw32-g++.exe -Weffc++ -Wfatal-errors -Wextra -Wall -std=c++11 -pg -g  -c 

"C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.cpp" -o 

"C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.o"

C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.cpp:8:7: error: expected nested 

name-specifier before 'namespace'
 
using namespace std;
       ^
compilation terminated due to -Wfatal-errors.
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 


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



using namespace std;
int main(){

	A use;   // A is the name of class in A.h file
	vector<string> user_Input;
	for (int i = 0; i < 3; ++i)
	{
		cin >> use.out_of(user_Input[i]);
	}
	use.print();  // print questions, scores, and answers

	return 0;
}
Last edited on
The error is a "A.h". Probably missing }; at the end of the class.

No, I checked A.h, and I have my }; at the end of the class.
The error is in A.h, show A.h


Also, the line numbers in the error message do not correspond with the code you've posted.
I solved the problem, I needed to include an extra namespace for all my .h files, and then include that namespace in my .cpp file like this:

using namespace test;
Topic archived. No new replies allowed.