error C2040: “str”:“std::string [11]”与“std::string”的间接寻址级别不同
环境是VS,我想定义一个全局string数组stdafx.cpp
程序代码:
#include "stdafx.h" string str[11]={"做一个大家都满意的鬼脸 ", "模仿脑白金广告,边唱边跳", "原地转30圈后唱校歌", "跪地作向一个人求婚状:如果我不向你求婚,我会后悔一辈子,因为你是我的惟一。", "与一个人正面对着十指 交扣,深情对视,深情朗诵骆宾王的《鹅》 ", "摆芙蓉姐姐的S形", "邀请一位同伴和自己一起一边做动作一边唱“我爱洗澡皮肤好好”", " 背起右边第一 个人", "穿的外套表演 张倾城之“我脱、我穿、我再脱、我再穿”", "男生做20个俯卧撑,女生做20个仰卧起坐", "抱着垃圾桶拍照", }; int i =0;
stdafx.h
程序代码:
// stdafx.h : 标准系统包含文件的包含文件, // 或是经常使用但不常更改的 // 特定于项目的包含文件 #pragma once // TODO: 在此处引用程序需要的其他头文件 #include<iostream> #include <string> using namespace std; extern string str; extern int i;
Form1.h
程序代码:
#pragma once #include <stdio.h> namespace 大冒险 { 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> /// Form1 摘要 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: 在此处添加构造函数代码 // } protected: /// <summary> /// 清理所有正在使用的资源。 /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Timer^ timer1; private: System::ComponentModel::IContainer^ components; protected: private: /// <summary> /// 必需的设计器变量。 /// </summary> #pragma region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); this->SuspendLayout(); // // textBox1 // this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) | System::Windows::Forms::AnchorStyles::Left) | System::Windows::Forms::AnchorStyles::Right)); this->textBox1->Font = (gcnew System::Drawing::Font(L"宋体", 50)); this->textBox1->Location = System::Drawing::Point(46, 12); this->textBox1->Multiline = true; this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(265, 118); this->textBox1->TabIndex = 0; this->textBox1->Text = L"大冒险开始"; // // button1 // this->button1->Font = (gcnew System::Drawing::Font(L"宋体", 15)); this->button1->Location = System::Drawing::Point(145, 187); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(110, 40); this->button1->TabIndex = 1; this->button1->Text = L"开始"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // timer1 // this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(385, 262); this->Controls->Add(this->button1); this->Controls->Add(this->textBox1); 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) { timer1->Enabled = true; textBox1->Text=str[i]; } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { if(i<=10){ i++; }else { i=0; } } }; }