Redefinition error

Hi i am sort of a newbie to C++ and i made an encryption/decryption program. but theres one problem i cant reserve bytes of memory for a string. my code is:

string ES;
ES.reserve(1000);

and it gives the following errors

CrypterGUI.cpp(9): error C2143: syntax error : missing ';' before '.'
1>CrypterGUI.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>CrypterGUI.cpp(9): error C2371: 'ES' : redefinition; different basic types
1> CrypterGUI.cpp(8) : see declaration of 'ES'



someone please help me
thanks in advance!
Last edited on
1
2
string ES;
ES.reserve(1000);

is that the whole code?
it's hard to find the problem if we can't see the codes
It seems that you should write

std::string ES;

provided that you included header <string>
Last edited on
heres the main file:


#include "stdafx.h"
#include "Crypter.h"

using namespace CrypterGUI;

string ES;
ES.reserve(1000);


[STAThreadAttribute]

int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Crypter());
return 0;
}
but the header file is too big ill give you the beginning part:

#pragma once

#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <msclr\marshal_cppstd.h>
//include ""Copystr.h"" when fixed
#include <Windows.h>
#include <WinUser.h>
#using <System.DLL>
#using <System.Drawing.DLL>
#using <System.Windows.Forms.DLL>


namespace CrypterGUI {

using namespace std;
using namespace msclr::interop;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Crypter
/// </summary>
public ref class Crypter : public System::Windows::Forms::Form
{
public:
Crypter(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Crypter()
{
if (components)
{
delete components;
}
}

private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;







private: System::Windows::Forms::ToolStripMenuItem^ exitAltF4ToolStripMenuItem;

private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ exitALTF4ToolStripMenuItem1;
private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem1;
private: System::Windows::Forms::Button^ button1;
and i tried std::string as well it didnt work
you tried using namespace std; ?
yeah its included in the namespace CrypterGUI
oh btw ES is a external/global string, and so where i called it externally, i just put
ES.reserve(1000);
and it worked
and actually i have one more problem
i tried using setclipboarddata() here is the code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <string>
#include <iostream>
#include <Windows.h>
#using <System.DLL>
#using <System.Windows.Forms.DLL>
using namespace std;
using namespace System;
using namespace System::Windows::Forms;




int copystr(const char* clipoutput)
	{
		const size_t len = strlen(clipoutput) + 1;

		HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
		memcpy(GlobalLock(hMem), clipoutput, len);
		GlobalUnlock(hMem);
		OpenClipboard(0);
		EmptyClipboard();
		SetClipboardData(CF_TEXT, hMem);
		MessageBox::Show("String has been copied to clipboard!", "Copied", MessageBoxButtons::OK, MessageBoxIcon::Information);
		CloseClipboard();
		return 0;
	}


and then i called it here:

1
2
3
4
5
6
7
8
9
10
11
12
13
private: System::Void Decrypt(System::Object^  sender, System::EventArgs^  e) {
				extern string ES;
				ES.reserve(1000);
				System::String^ ESd;
				decrypt(ES, p, ESd);
				System::Windows::Forms::DialogResult copy;
				copy = MessageBox::Show(ESd + ". Copy? \n", "Encrypted String", MessageBoxButtons::YesNo, MessageBoxIcon::Information);
				if (copy == System::Windows::Forms::DialogResult::Yes)
				{
					MessageBox::Show("String copied to clipboard!", "Sorry", MessageBoxButtons::OK, MessageBoxIcon::Information);
					copystr(ES.c_str());
				}
		 }


and i get the following errors:


1
2
3
4
5
6
7
8
9
1>CrypterGUI.obj : error LNK2028: unresolved token (0A00006C) "extern "C" int __stdcall CloseClipboard(void)" (?CloseClipboard@@$$J10YGHXZ) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A00006E) "extern "C" void * __stdcall SetClipboardData(unsigned int,void *)" (?SetClipboardData@@$$J18YGPAXIPAX@Z) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A00006F) "extern "C" int __stdcall EmptyClipboard(void)" (?EmptyClipboard@@$$J10YGHXZ) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2028: unresolved token (0A000070) "extern "C" int __stdcall OpenClipboard(struct HWND__ *)" (?OpenClipboard@@$$J14YGHPAUHWND__@@@Z) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall CloseClipboard(void)" (?CloseClipboard@@$$J10YGHXZ) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern "C" void * __stdcall SetClipboardData(unsigned int,void *)" (?SetClipboardData@@$$J18YGPAXIPAX@Z) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall EmptyClipboard(void)" (?EmptyClipboard@@$$J10YGHXZ) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>CrypterGUI.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall OpenClipboard(struct HWND__ *)" (?OpenClipboard@@$$J14YGHPAUHWND__@@@Z) referenced in function "extern "C" int __clrcall copystr(char const *)" (?copystr@@$$J0YMHPBD@Z)
1>C:\C++\Projects\Debug\CrypterGUI.exe : fatal error LNK1120: 8 unresolved externals



can someone please tell me what i did wrong?
thanks in advance!
Topic archived. No new replies allowed.