Форум программистов, компьютерный форум, киберфорум
C++/CLI
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.82/11: Рейтинг темы: голосов - 11, средняя оценка - 4.82
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
1

Hello World и нуб

09.02.2011, 20:45. Показов 2038. Ответов 14
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте Добрые Люди!
Пытаюсь что нибудь сделать, создал лейбел, кнопочку и хочу чтобы при нажатии в лейбле появились вот эти хитрые операции со строками...

C++
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
 
namespace Hello {
 
    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 Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }
 
    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^  label1;
    protected: 
    private: System::Windows::Forms::Button^  button1;
 
    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(193, 35);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(0, 13);
            this->label1->TabIndex = 0;
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(32, 134);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(111, 35);
            this->button1->TabIndex = 1;
            this->button1->Text = L"Кнопочка";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(470, 229);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->label1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {   
  string s1, s2; // Пустые строки
  string s3 = "Hello, World."; // Инициализированная строка
  string s4("I am"); // Другой пример инициализации
  s2 = "Today"; // Присваивание
  s1 = s3 + " " + s4; // Слияние строк
  s1 += " 8 "; // Присоединение новых символов к строке
  label1->Text = s1 + s2 + "!";
             }
    };
}
На что MVS C++ мне отвечает

Error 1 error C2065: 'string' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 91 1 Hello
Error 2 error C2146: syntax error : missing ';' before identifier 's1' c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 91 1 Hello
Error 3 error C2065: 's1' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 91 1 Hello
Error 4 error C2065: 's2' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 91 1 Hello
Error 5 error C2065: 'string' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 92 1 Hello
Error 6 error C2146: syntax error : missing ';' before identifier 's3' c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 92 1 Hello
Error 7 error C2065: 's3' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 92 1 Hello
Error 8 error C2065: 'string' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 93 1 Hello
Error 9 error C2146: syntax error : missing ';' before identifier 's4' c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 93 1 Hello
Error 10 error C3861: 's4': identifier not found c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 93 1 Hello
Error 11 error C2065: 's2' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 94 1 Hello
Error 12 error C2065: 's1' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 95 1 Hello
Error 13 error C2065: 's3' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 95 1 Hello
Error 14 error C2065: 's4' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 95 1 Hello
Error 15 error C2065: 's1' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 96 1 Hello
Error 16 error C2065: 's1' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 97 1 Hello
Error 17 error C2065: 's2' : undeclared identifier c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 97 1 Hello
Помогите исправить ошибочку уже какой час маюсь... Hello.cpp выглядит так
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Hello.cpp : main project file.
 
#include "stdafx.h"
#include "Form1.h"
#include <string>
#include <iostream>
 
using namespace std;
using namespace Hello;
 
[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 Form1());
    return 0;
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
09.02.2011, 20:45
Ответы с готовыми решениями:

Компиляция простейшего примера, или "Ещё один нуб с Hello World"
Проблема такая: пытаюсь собрать простейший пример уже третий (точнее - уже минут 40, как четвёртый)...

Поменять слова местами то есть Hello World > World Hello C++
Ребят всем привет помогите решить задачку: Имеется предварительно созданный текстовый файл,...

я нуб
S=(a^2+2*a*b+b^2)/(a-1) a и b любое с клавы если S&gt;100 тогда закончить программу, иначе ввести...

я нуб)
программу написал а куда она сохраняетсяя?

14
4773 / 2582 / 894
Регистрация: 29.11.2010
Сообщений: 5,590
09.02.2011, 20:49 2
В первый файл добавьте
C++
1
using namespace std;
0
686 / 613 / 43
Регистрация: 13.01.2011
Сообщений: 1,722
09.02.2011, 20:50 3
*.cpp?
0
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
09.02.2011, 20:54  [ТС] 4
А куда именно?
добавил где все using nameaspace и не чего нового...

Добавлено через 1 минуту
Цитата Сообщение от zulkis Посмотреть сообщение
*.cpp?
мммм
Hello.cpp
0
4773 / 2582 / 894
Регистрация: 29.11.2010
Сообщений: 5,590
09.02.2011, 20:58 5
Еще добавьте
C++
1
#include <string>
0
Freelance
Эксперт С++
2891 / 1826 / 356
Регистрация: 09.09.2010
Сообщений: 3,841
09.02.2011, 21:11 6
Там вроде надо юзать не просто std::string а String^
0
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
09.02.2011, 21:22  [ТС] 7
Цитата Сообщение от lemegeton Посмотреть сообщение
Еще добавьте
C++
1
#include <string>
Тык а вопрос а куда именно?

Добавлено через 1 минуту
Цитата Сообщение от asics Посмотреть сообщение
Там вроде надо юзать не просто std::string а String^
Куда не добавлял, вызывает еще большее количество ошибок )
0
236 / 173 / 25
Регистрация: 13.11.2010
Сообщений: 425
09.02.2011, 21:37 8
marioneTkka,
C++
1
System::String^ str="Text";
У меня компилирует.
1
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
09.02.2011, 21:42  [ТС] 9
Цитата Сообщение от almazsr Посмотреть сообщение
marioneTkka,
C++
1
System::String^ str="Text";
У меня компилирует.
Скажи пожалуйста а куда ты именно добавил эту строчку?
0
216 / 216 / 33
Регистрация: 26.12.2010
Сообщений: 691
09.02.2011, 21:56 10
C++
1
2
3
  string^ s1, s2; // Пустые строки
  string^ s3 = "Hello, World."; // Инициализированная строка
  string^ s4 = ("I am"); // Другой пример инициализации
1
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
09.02.2011, 22:06  [ТС] 11
Все уже намного лучше =)

C++
1
2
3
4
5
6
7
8
9
10
11
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {   
  System::String^ s1, s2; // Пустые строки
  System::String^ s3 = "Hello, World."; // Инициализированная строка
  System::String^ s4("I am"); // Другой пример инициализации
  s2 = "Today"; // Присваивание
  s1 = s3 + " " + s4; // Слияние строк
  s1 += " 8 "; // Присоединение новых символов к строке
  label1->Text = s1 + s2 + "!";
             }
    };
}
Только осталась последняя ошибочка

Error 1 error C3149: 'System::String' : cannot use this type here without a top-level '^' c:\users\puppetmaster\documents\visual studio 2010\projects\hello\hello\Form1.h 91 1 Hello
0
Эксперт С++
5828 / 3479 / 358
Регистрация: 08.02.2010
Сообщений: 7,448
10.02.2011, 04:55 12
Попробуй изменить строку System::String^ s1, s2; на System::String ^s1, ^s2;
0
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
10.02.2011, 12:31  [ТС] 13
Цитата Сообщение от Nameless One Посмотреть сообщение
Попробуй изменить строку System::String^ s1, s2; на System::String ^s1, ^s2;
Не помогло =( еще больше ошибок только стало...
0
216 / 216 / 33
Регистрация: 26.12.2010
Сообщений: 691
10.02.2011, 19:55 14
какой компилятор у вас?
у меня vs 2008 и такой код
C++
1
2
System::String ^str, ^str2;
str = "test";
прекрасно компилируется..
0
0 / 0 / 0
Регистрация: 09.02.2011
Сообщений: 7
11.02.2011, 15:57  [ТС] 15
Цитата Сообщение от NiRamz Посмотреть сообщение
какой компилятор у вас?
у меня vs 2008 и такой код
C++
1
2
System::String ^str, ^str2;
str = "test";
прекрасно компилируется..
У меня 2010...
Может не допустимы такие операции над строками ?
C++
1
2
3
4
s2 = "Today"; // Присваивание
  s1 = s3 + " " + s4; // Слияние строк
  s1 += " 8 "; // Присоединение новых символов к строке
  label1->Text = s1 + s2 + "!";
0
11.02.2011, 15:57
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
11.02.2011, 15:57
Помогаю со студенческими работами здесь

Я нуб спасите2
Все тот же вопрос,надо на php devel studio 2.0.0 создать вирус(винлок)( без вопросов ,,зачем?&quot;...

Я нуб спасите
Хочу создать таймер от 5 минут до 0 и чтобы это отбражалось в label-e (чтобы я цыфры видел) и еще...

inputbox, нуб
Вообщем очень быстро нужно выучить php, раньше не работал ни с php, ни с javascript. Сделал код,...

Нуб и сети
Такая ситуация: есть нуб (то есть я), который хочет написать хотя бы чат на с++. Проблема в том,...

Примитивное задание, а я нуб
Дано задание, помогите решить!(Я заочник, и из 3 лекций, именно эту пропустил) Из заданного...

о функциях (элементарно, но я же нуб)
Пишу в компилятор следующее: #include &lt;cstdlib&gt; #include &lt;iostream&gt; int Sum (int a, int b) {...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
15
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru