简体   繁体   English

想知道我的程序做错了什么[暂停]

[英]Wondering what I did wrong with my program [on hold]

#include <iostream>
#include <string>

using namespace std;
/*
Author: Isaiah Santos
Purpose: To spitout date in a specific Order
*/

main()
{

string >> month , day , year ,;

cout << "Hello My Name Is Isaiah Santos \n";

cout << "Enter The Current Month (1-12): \n";
    cin >> month;

cout << "Enter The Numberical Number For Today (1-31): \n";
    cin >> day;

cout << "Enter The Year (YYYY) \n" >>
    cin >> year;

string datestring = "The Date Is  " + year "/" + day "/" + month + ".";
cout << datestring;


    return 0;
}

Here is the build messages I got while attempting to compile:这是我在尝试编译时收到的构建消息:

error: expected Expression错误:预期表达式

error: redefinition of datesting错误:重新定义日期

error: invalid operands to binary expression ('const char *' and 'const char [2]')|错误:二进制表达式的操作数无效('const char *' 和 'const char [2]')|

It was working but the format for my output was wrong, so I changed it, but now it won't compile, so I was wondering what I messed up.它可以工作,但是我的 output 的格式错误,所以我更改了它,但现在它无法编译,所以我想知道我搞砸了什么。 Still kinda new to c++. c++ 还是有点新的。 Thank you all for the help so far and no none of it was copy pasta just typing in what my friend told me.到目前为止,感谢大家的帮助,没有任何一个是复制意大利面,只是输入我朋友告诉我的内容。 Also I have tried googling the error codes and all the ones I have read haven't been of much help.我也试过用谷歌搜索错误代码,我读过的所有代码都没有太大帮助。

Update this line,更新这一行,

string month, day, year;

Also this,还有这个,

string datestring = "The Date Is " + year + "/" + day "/" + month + ".";

In C++ there are two kinds of strings, arrays of characters and the std::string class.在 C++ 中有两种字符串,字符 arrays 和std::string class。 Addition acting to concatenate strings only works if the first is of type std::string .仅当第一个std::string类型时,连接字符串的加法才有效。 You can fix your code easily:您可以轻松地修复代码:

string datestring = string("The Date Is  ") + year + "/" + day "/" + month + ".";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM