【发布时间】:2017-10-13 18:11:06
【问题描述】:
我昨天刚开始学习 C++,我有 Java 的基本知识,并且正在尝试基础知识。我正在尝试制作一个非常基本的程序来理解这种语言的语法。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string bacon = "How many characters are in the following? ";
string chedder = "icecream";
string cheSize = chedder.size();
string snow = bacon + " " + "\"" + chedder + "\"" + "The number is : " + cheSize;
cout << snow;
return 0;
}
我做错了什么?
另外,我注意到 cout 不能组合多个字符串,例如
cout << snow + chedder;
没用。
这是什么原因?感谢您的宝贵时间!
【问题讨论】:
-
string cheSize = chedder.size();size 返回 int 而不是 string。 -
在使用东西之前先reading the famous manual怎么样?
-
你不能通过做一些随机的事情并询问stackoverflow为什么它不起作用来学习C++。
标签: c++ string operator-overloading