skakun Temat założony przez niniejszego użytkownika |
[visualC++]missing type specifier-string » 2015-06-20 10:41:16 Witam. Korzystam z szablonu do robienia aplikacji okienkowych w visual studio 2010. Środowisko zamieszcza w projekcie jakieś własne biblioteki. Za każdym razem jak używam zmiennej typu string kompilator wyrzuca mi: missing type specifier Dodałem w głównym kodzie #include<string> a przy deklaracji próbowałem std::string czy string::string. Żadnych zmian.Jak temu zaradzić? |
|
akwes |
» 2015-06-20 12:25:37 Podaj przykładowy kod, w którym pojawia się ten problem oraz dokładny log kompilacji. |
|
skakun Temat założony przez niniejszego użytkownika |
» 2015-06-20 13:36:56
#include "stdafx.h" #include "Form1.h" #include <string>
using namespace Kalkulator1;
void nowa_cyfra( string & liczba, string bufor ) { liczba = liczba + bufor; } [ STAThreadAttribute ] int main( array < System::String ^> ^ args ) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault( false ); Application::Run( gcnew Form1() ); return 0; }
#pragma once
namespace Kalkulator1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class Form1 : public System::Windows::Forms::Form { public: Form1( void ) { InitializeComponent(); } protected: ~Form1() { if( components ) { delete components; } } private: System::Windows::Forms::Button ^ button1; protected: private: System::Windows::Forms::Button ^ button2; private: System::Windows::Forms::Button ^ button3; private: System::Windows::Forms::Button ^ button4; private: System::Windows::Forms::Button ^ button5; private: System::Windows::Forms::Button ^ button6; private: System::Windows::Forms::Button ^ button7; private: System::Windows::Forms::Button ^ button8; private: System::Windows::Forms::Button ^ button9; private: System::Windows::Forms::Button ^ button0; private: System::Windows::Forms::Button ^ plus; private: System::Windows::Forms::Button ^ minus; private: System::Windows::Forms::Button ^ razy; private: System::Windows::Forms::Button ^ przez; private: System::Windows::Forms::Button ^ buttonc; private: System::Windows::Forms::TextBox ^ ekran; private: System::ComponentModel::Container ^ components; #pragma region Windows Form Designer generated code string przed_znakiem, po_znaku, bufor; bool byl_znak = false; private: System::Windows::Forms::Button ^ kropka; void InitializeComponent( void ) { this->button1 =( gcnew System::Windows::Forms::Button() ); this->button2 =( gcnew System::Windows::Forms::Button() ); this->button3 =( gcnew System::Windows::Forms::Button() ); this->button4 =( gcnew System::Windows::Forms::Button() ); this->button5 =( gcnew System::Windows::Forms::Button() ); this->button6 =( gcnew System::Windows::Forms::Button() ); this->button7 =( gcnew System::Windows::Forms::Button() ); this->button8 =( gcnew System::Windows::Forms::Button() ); this->button9 =( gcnew System::Windows::Forms::Button() ); this->button0 =( gcnew System::Windows::Forms::Button() ); this->plus =( gcnew System::Windows::Forms::Button() ); this->minus =( gcnew System::Windows::Forms::Button() ); this->razy =( gcnew System::Windows::Forms::Button() ); this->przez =( gcnew System::Windows::Forms::Button() ); this->buttonc =( gcnew System::Windows::Forms::Button() ); this->ekran =( gcnew System::Windows::Forms::TextBox() ); this->kropka =( gcnew System::Windows::Forms::Button() ); this->SuspendLayout(); this->button1->Location = System::Drawing::Point( 31, 106 ); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size( 40, 33 ); this->button1->TabIndex = 0; this->button1->Text = L"1"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler( this, & Form1::button1_Click ); this->button2->Location = System::Drawing::Point( 77, 106 ); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size( 40, 33 ); this->button2->TabIndex = 1; this->button2->Text = L"2"; this->button2->UseVisualStyleBackColor = true; this->button3->Location = System::Drawing::Point( 123, 106 ); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size( 40, 33 ); this->button3->TabIndex = 2; this->button3->Text = L"3"; this->button3->UseVisualStyleBackColor = true; this->button4->Location = System::Drawing::Point( 31, 145 ); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size( 40, 33 ); this->button4->TabIndex = 3; this->button4->Text = L"4"; this->button4->UseVisualStyleBackColor = true; this->button5->Location = System::Drawing::Point( 77, 145 ); this->button5->Name = L"button5"; this->button5->Size = System::Drawing::Size( 40, 33 ); this->button5->TabIndex = 4; this->button5->Text = L"5"; this->button5->UseVisualStyleBackColor = true; this->button6->Location = System::Drawing::Point( 123, 145 ); this->button6->Name = L"button6"; this->button6->Size = System::Drawing::Size( 40, 33 ); this->button6->TabIndex = 5; this->button6->Text = L"6"; this->button6->UseVisualStyleBackColor = true; this->button7->Location = System::Drawing::Point( 31, 184 ); this->button7->Name = L"button7"; this->button7->Size = System::Drawing::Size( 40, 33 ); this->button7->TabIndex = 6; this->button7->Text = L"7"; this->button7->UseVisualStyleBackColor = true; this->button8->Location = System::Drawing::Point( 77, 184 ); this->button8->Name = L"button8"; this->button8->Size = System::Drawing::Size( 40, 33 ); this->button8->TabIndex = 7; this->button8->Text = L"8"; this->button8->UseVisualStyleBackColor = true; this->button9->Location = System::Drawing::Point( 123, 184 ); this->button9->Name = L"button9"; this->button9->Size = System::Drawing::Size( 40, 33 ); this->button9->TabIndex = 8; this->button9->Text = L"9"; this->button9->UseVisualStyleBackColor = true; this->button0->Location = System::Drawing::Point( 77, 223 ); this->button0->Name = L"button0"; this->button0->Size = System::Drawing::Size( 40, 33 ); this->button0->TabIndex = 9; this->button0->Text = L"9"; this->button0->UseVisualStyleBackColor = true; this->plus->Location = System::Drawing::Point( 200, 106 ); this->plus->Name = L"plus"; this->plus->Size = System::Drawing::Size( 40, 33 ); this->plus->TabIndex = 10; this->plus->Text = L"+"; this->plus->UseVisualStyleBackColor = true; this->minus->Location = System::Drawing::Point( 246, 106 ); this->minus->Name = L"minus"; this->minus->Size = System::Drawing::Size( 40, 33 ); this->minus->TabIndex = 11; this->minus->Text = L"-"; this->minus->UseVisualStyleBackColor = true; this->razy->Location = System::Drawing::Point( 200, 145 ); this->razy->Name = L"razy"; this->razy->Size = System::Drawing::Size( 40, 33 ); this->razy->TabIndex = 12; this->razy->Text = L"X"; this->razy->UseVisualStyleBackColor = true; this->razy->Click += gcnew System::EventHandler( this, & Form1::button13_Click ); this->przez->Location = System::Drawing::Point( 246, 145 ); this->przez->Name = L"przez"; this->przez->Size = System::Drawing::Size( 40, 33 ); this->przez->TabIndex = 13; this->przez->Text = L":"; this->przez->UseVisualStyleBackColor = true; this->buttonc->Location = System::Drawing::Point( 234, 57 ); this->buttonc->Name = L"buttonc"; this->buttonc->Size = System::Drawing::Size( 40, 33 ); this->buttonc->TabIndex = 14; this->buttonc->Text = L"c"; this->buttonc->UseVisualStyleBackColor = true; this->ekran->Location = System::Drawing::Point( 40, 20 ); this->ekran->Name = L"ekran"; this->ekran->Size = System::Drawing::Size( 234, 20 ); this->ekran->TabIndex = 15; this->ekran->TextChanged += gcnew System::EventHandler( this, & Form1::textBox1_TextChanged ); this->kropka->Location = System::Drawing::Point( 200, 184 ); this->kropka->Name = L"kropka"; this->kropka->Size = System::Drawing::Size( 40, 33 ); this->kropka->TabIndex = 16; this->kropka->Text = L"."; this->kropka->UseVisualStyleBackColor = true; this->AutoScaleDimensions = System::Drawing::SizeF( 6, 13 ); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size( 299, 262 ); this->Controls->Add( this->kropka ); this->Controls->Add( this->ekran ); this->Controls->Add( this->buttonc ); this->Controls->Add( this->przez ); this->Controls->Add( this->razy ); this->Controls->Add( this->minus ); this->Controls->Add( this->plus ); this->Controls->Add( this->button0 ); this->Controls->Add( this->button9 ); this->Controls->Add( this->button8 ); this->Controls->Add( this->button7 ); this->Controls->Add( this->button6 ); this->Controls->Add( this->button5 ); this->Controls->Add( this->button4 ); this->Controls->Add( this->button3 ); this->Controls->Add( this->button2 ); this->Controls->Add( this->button1 ); this->Name = L"Form1"; this->Text = L"Form1"; this->ResumeLayout( false ); this->PerformLayout(); } #pragma endregion private: System::Void button13_Click( System::Object ^ sender, System::EventArgs ^ e ) { } private: System::Void textBox1_TextChanged( System::Object ^ sender, System::EventArgs ^ e ) { } private: System::Void button1_Click( System::Object ^ sender, System::EventArgs ^ e ) { if( !byl_znak ) nowa_cyfra( przed_znakiem, "1" ); else nowa_cyfra( za_znakiem, "1" ); } }; }
1>------ Build started: Project: Kalkulator1, Configuration: Debug Win32 ------ 1> Kalkulator1.cpp 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(72): error C2146: syntax error : missing ';' before identifier 'przed_znakiem' 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(72): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(72): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(72): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(72): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(73): error C3845: 'Kalkulator1::Form1::byl_znak': only static data members can be initialized inside a ref class or value type 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(288): error C2065: 'przed_znakiem' : undeclared identifier 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(288): error C3861: 'nowa_cyfra': identifier not found 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(289): error C2065: 'za_znakiem' : undeclared identifier 1>c:\users\krzys\documents\visual studio 2010\projects\kalkulator1\kalkulator1\Form1.h(289): error C3861: 'nowa_cyfra': identifier not found 1>Kalkulator1.cpp(9): error C2065: 'string' : undeclared identifier 1>Kalkulator1.cpp(9): error C2065: 'liczba' : undeclared identifier 1>Kalkulator1.cpp(9): error C2065: 'string' : undeclared identifier 1>Kalkulator1.cpp(9): error C2146: syntax error : missing ')' before identifier 'bufor' 1>Kalkulator1.cpp(9): error C2182: 'nowa_cyfra' : illegal use of type 'void' 1>Kalkulator1.cpp(9): error C2078: too many initializers 1>Kalkulator1.cpp(9): error C2059: syntax error : ')' 1>Kalkulator1.cpp(10): error C2143: syntax error : missing ';' before '{' 1>Kalkulator1.cpp(10): error C2447: '{' : missing function header (old-style formal list?) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
pekfos |
» 2015-06-20 13:41:23 To nie jest C++. |
|
skakun Temat założony przez niniejszego użytkownika |
» 2015-06-20 13:44:59 W którym miejscu? |
|
pekfos |
» 2015-06-20 13:45:48 Cały ten, wygenerowany przez Visuala, kod nie jest w C++. |
|
Monika90 |
» 2015-06-20 14:25:56 Żeby używać typu std::string należy napisać #include <string>. Jeżeli chcesz pominąć przedrostek std:: to musisz napisać using std::string; albo using namespace std; Wszystko to musi znaleźć się w pliku przed miejscem w którym chcesz używać stringa.
Ale to i tak Ci nic nie da bo Windows Forms nic nie wie o std::string. |
|
skakun Temat założony przez niniejszego użytkownika |
» 2015-06-20 15:07:37 A jaki typ przechowuje tu ciągi znaków, jak zmienna text? |
|
« 1 » 2 |