C++ 包括字符串
C++ including string
嘿,我正在尝试创建 Windows 表单应用程序,但我在定义字符串时遇到问题
Fam.cpp
#include "Fam.h"
#include "iostream"
#include "string"
using namespace std;
using namespace Project1;
[STAThread]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Fam());
return 0;
}
Fam.h的一部分
#pragma once
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
int IloscBD1=0, IloscBD2=0, IloscPD1, IloscPD2, Suma, I, J, Punkty, P1, P2, P3, P4, P5, P6, Druzyna;
string a;
这是我遇到的错误
Error 1 error C2146: syntax error : missing ';' before identifier 'a'
Error 2 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int
我也试过改变字符串a;到std::string一个;但后来我收到了这些错误:
Error 1 error C2039: 'string' : is not a member of 'std'
Error 2 error C2146: syntax error : missing ';' before identifier 'a'
Error 3 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int
嗯,你必须在你的 header 中包含字符串,因为那是你使用它的地方。
Fam.h的一部分
#pragma once
#include <string>
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
int IloscBD1=0, IloscBD2=0, IloscPD1, IloscPD2, Suma, I, J, Punkty, P1, P2, P3, P4, P5, P6, Druzyna;
std::string a;
}
嘿,我正在尝试创建 Windows 表单应用程序,但我在定义字符串时遇到问题
Fam.cpp
#include "Fam.h"
#include "iostream"
#include "string"
using namespace std;
using namespace Project1;
[STAThread]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Fam());
return 0;
}
Fam.h的一部分
#pragma once
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
int IloscBD1=0, IloscBD2=0, IloscPD1, IloscPD2, Suma, I, J, Punkty, P1, P2, P3, P4, P5, P6, Druzyna;
string a;
这是我遇到的错误
Error 1 error C2146: syntax error : missing ';' before identifier 'a'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我也试过改变字符串a;到std::string一个;但后来我收到了这些错误:
Error 1 error C2039: 'string' : is not a member of 'std'
Error 2 error C2146: syntax error : missing ';' before identifier 'a'
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
嗯,你必须在你的 header 中包含字符串,因为那是你使用它的地方。
Fam.h的一部分
#pragma once
#include <string>
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
int IloscBD1=0, IloscBD2=0, IloscPD1, IloscPD2, Suma, I, J, Punkty, P1, P2, P3, P4, P5, P6, Druzyna;
std::string a;
}