非法字符?程序運(yùn)行可以啊
#include <iostream>
#include<stdlib.h>
#include <string>
using namespace std;
/**
? * 定義類:Student
? * 數(shù)據(jù)成員:名字、年齡
? */
class student
{
public:
? ? // 定義數(shù)據(jù)成員名字 m_strName 和年齡 m_iAge
? ? string m_strName;
? ? string m_iAge;
};
int main()
{
? ? // 實(shí)例化一個(gè)Student對(duì)象stu
? ? student stu;
? ? // 設(shè)置對(duì)象的數(shù)據(jù)成員
? ? stu.m_strName = "慕課網(wǎng)";
? ? stu.m_iAge = "2";
? ??
? ? // 通過cout打印stu對(duì)象的數(shù)據(jù)成員
? ? cout << "student name is " << stu.m_strName << endl<<"student age is "<<stu.m_iAge<<endl;
? ??
? ? system("pause");
? ? return 0;
}
2016-11-06
為什么?stu.m_strName="慕課網(wǎng)";這個(gè)不能改成?stu.m_strName("慕課網(wǎng)");
之前實(shí)例
string name="zhangsan";
string hobby=("football");
我用這兩種代換在之前的那個(gè)C++初始化string里面的那個(gè)程序,這個(gè)都可以啊
2016-01-15
我運(yùn)行了一下,沒有問題啊。還有年齡怎么也用string
2016-01-15
我運(yùn)行了一下,沒有問題啊。還有年齡怎么也用string