【发布时间】:2019-03-03 04:46:59
【问题描述】:
这是我关于堆栈溢出的第一个问题。我遇到编译器问题,想知道是否有人可以帮助我找出原因。
这是我每次尝试编译时都会收到的不幸错误消息。
//*************************************************************************
// This program uses array with a for loop control structure to prompt the user to enter their most convenient days of the week to work
#include <iostream>
using namespace std;
#include <array>
#include <cstddef>
int main() {
int whichDay = 0;
array< string, 7> daysOfweek =
{
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"Friday",
"saturday"
};
for (size_t x= 0; x< daysOfweek.size(); x++)
{
cout << daysOfWeek[x] << endl;
};
cout << "enter your work day: " ;
cin >> whichDay;
cout << daysOfWeek[whichDay] += 1
return 0;
}
【问题讨论】:
-
prog.cpp: In function 'int main()': prog.cpp:25:10: error: 'daysOfWeek' 未在此范围内声明 cout
-
一个简单的错字
daysOfWeek[x]不应该有大写W -
谢谢你迈克尔!我仍然有一些错误,它不会让我对 std:: 使用 = 运算符,它不会让我将参数 1 转换为 std:: 但是我对如何更改语法感到困惑
-
daysOfweek[whichDay] 是一个字符串,所以 +=1 无效。
-
运行 clang_format 或其他格式化工具会突出一些错别字。