I'm trying to write a GUI program where I want to use both strings and vectors, but the computer won't recognize them no matter where I try to include <string> and <vector>. Can you tell me where in the code I need to put my includes and my std namespace?

Recommended Answers

All 7 Replies

I'm trying to write a GUI program where I want to use both strings and vectors, but the computer won't recognize them no matter where I try to include <string> and <vector>. Can you tell me where in the code I need to put my includes and my std namespace?

Please post the code you tried, and a few of the error messages. Placement of the headers should be no different than non-gui programs.

I've tried placing the headers at the top of the code with combinations like:

#include<vector>
#include<string>
using namespace std;
#pragma once //(given to me)

...

#pragma once
#include<vector>
#include<string>
using namespace std;

...

but every time I have received error messages when trying to declare a new string or vector:

error C4368: cannot define 'test' as a member of managed 'dndai::Form1': mixed types are not supported

Does that help?

1) In *.cpp file do NOT use that pragma -- its only intended for include files

2) I just created a CLR Windows Forms application and had no problem including those files using VC++ 2008 Express. I also added them to the .h file with no problems.

#include "stdafx.h"
#include<vector>
#include<string>
using namespace std;
#include "Form1.h"

using namespace winform;
// 
// rest of *.cpp code here

Ok, so really I should just delete the pragma?

I never really thought about that since it was automatically included in the code.
------
That didn't work, I get the same errors.

When I tried the code you had, including "stdafx" and Form1, I received the error:

fatal error C1014: too many include files : depth = 1024

Delete all compiler-generated files, zip up the remainder and attach it to this thread so that we can see exactly what you are trying to do.

I was unable to attach the zipped file. But considering all that we've looked through, I'm not sure if it would help. Maybe I can find a different way to do this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.