相关疑难解决方法(0)

什么是C字符串和C++字符串之间的区别?

什么是C Strings和C++字符串之间的区别.特别是在进行动态内存分配时

c c++ string

12
推荐指数
2
解决办法
2万
查看次数

我什么时候在C++程序的开头使用'#include <string>'?

#include <string>对程序开始时的使用感到困惑.例如,在下面的代码中,我不使用,#include <string>但该函数在运行时仍会打印出字符串"Johnny的最爱号码".

#include <iostream>
using namespace std;

void printVariable(int number){
    cout << "Johnny's favorite number is" << number << endl
}
Run Code Online (Sandbox Code Playgroud)

但是,在下面的代码中,它确实包含#include <string>.

#include <iostream>
#include <string>
using namespace std;

class Var{
    public:
        void setName(string x){
            name = x;
        }

        string getName(){
           return name;
        }
   private:
       string name;
};

int main(){
    Var Classy;
    Classy.setName("Johnny Bravo");
    cout << Classy.getName() << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我只#include <string>在变量表示字符串时使用吗?

c++ string

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

string ×2

c ×1