超级粽子吧 关注:98,596贴子:20,044,910

会C/C++的程序牛人进来!!!考你们一个初级问题!!!

只看楼主收藏回复

char * tmp = "abcdef";
string tmpStr;

如何把tmp的值赋给tmpStr?


1楼2005-12-08 12:42回复
    那么简单的问题都木有人回答啊!!!
    粽吧没人了啊!!


    2楼2005-12-08 12:48
    回复
      2025-08-14 14:22:33
      广告
      不感兴趣
      开通SVIP免广告
      • 222.95.175.*
      strcpy


      3楼2005-12-08 12:53
      回复
        strcpy(tmpStr,tmp);


        删除|4楼2005-12-08 12:55
        回复
          strcpy不work~~~
          char * strcpy ( char * dest, const char * src );

          如果是string的话,会出错~~~ 

          error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
           No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


          5楼2005-12-08 12:56
          回复
            你有没有把头文件包含进去啊?


            删除|6楼2005-12-08 12:59
            回复
              char * tmp = "abcdef"; 
              string tmpStr; 

              tempStr=string(tmp);


              7楼2005-12-08 13:01
              回复
                有啊。
                #include <string.h>
                #include <stdio.h>
                ...


                8楼2005-12-08 13:01
                回复
                  2025-08-14 14:16:33
                  广告
                  不感兴趣
                  开通SVIP免广告
                  • 221.5.154.*
                  #include<string.h>


                  9楼2005-12-08 13:02
                  回复
                    tmpStr = tmp


                    10楼2005-12-08 13:04
                    回复
                      tempStr=string(tmp); 

                      tmpStr = tmp 

                      用这两个,编译通过,
                      但运行时就死在那里了


                      11楼2005-12-08 13:06
                      回复
                        strncpy


                        12楼2005-12-08 13:06
                        回复
                          哦,不好意思,偶们主管说了,strcpy的目的不能是strcpy的,你直接强制类型转换就可以了,不好意思,误导你了..........


                          删除|13楼2005-12-08 13:06
                          回复
                            不能是string!!!!!!


                            删除|14楼2005-12-08 13:07
                            回复
                              2025-08-14 14:10:33
                              广告
                              不感兴趣
                              开通SVIP免广告
                              程序段不完整


                              15楼2005-12-08 13:08
                              回复