| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2365 人关注过本帖
标题:error C2040: “str”:“std::string [11]”与“std::string”的间接寻址级 ...
只看楼主 加入收藏
hxy19931129
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2011-4-6
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:5 
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;
                 }
             }
    };
}

搜索更多相关主题的帖子: color 
2012-12-17 21:48
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:20 
extern string str;
这个是否改成extern string str[11];??

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2012-12-17 22:32
hxy19931129
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2011-4-6
收藏
得分:0 
回复 2楼 yuccn
变成了楼下的...

[ 本帖最后由 hxy19931129 于 2012-12-17 23:19 编辑 ]
2012-12-17 23:17
hxy19931129
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2011-4-6
收藏
得分:0 
回复 2楼 yuccn
Form1.h(116): error C2664: “void System::Windows::Forms::Control::Text::set(System::String ^)”: 不能将参数 1 从“std::string”转换为“System::String ^”
1>          没有用户定义的转换运算符,或者
1>          没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
2012-12-17 23:18
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:0 
把所有的代码打包发出来看看~

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2012-12-18 00:47
hxy19931129
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2011-4-6
收藏
得分:0 
回复 5楼 yuccn
上面就是全部代码
2012-12-18 10:20
快速回复:error C2040: “str”:“std::string [11]”与“std::string”的间接寻 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015632 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved