我创建了这个程序,由于某种原因,Visual Studio正在给出这个'警告'(“预处理器指令之后的意外标记 - 期望换行符”),同时还发现错误似乎引用了从行的一行向下的内容编译器声称他们正在使用。对于即时,错误Carat Error似乎是指仅适用one line down的内容。因此,我相信在程序的标题中必定会出现严重错误,但我不确定。这是代码:
//1/4/2017
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
void getNewItem();
void displayItems();
void displayRand();
vector<string> vecItems;
int main()
{
//declaration phase
int intInput;
string strNewItem;
cout << "Random Item Generator" << endl << "Written by #XXXXX" << endl << "1. Add Item" << endl << "2. Display All Items " << endl << "3. Display Random Item" << endl << "4. Quit" << endl;
while (intInput != 4)
{
cin >> intInput;
switch (intInput)
{
case 1:
getNewItem();
break;
case 2:
displayItems();
break;
case 3:
displayRand();
break;
}
}
return 0;
}
void getNewItem() {
string strNewItem;
cin >> strNewItem;
vecItems.push_back(strNewItem);
}
void displayItems() {
for (int i = 0; i < vecItems.size(); i++) {
cout << vecItems.at(i) << endl;
}
}
void displayRand() {
int intRandIndex;
//random number generator
srand((unsigned)time(0));
intRandIndex = rand() % 10;
cout << vecItems.at(intRandIndex) << endl;
}
截屏1
截屏2
编辑:Visual Studio版本是Visual Studio 2015,我已经重新编译并在全新的项目中运行无济于事。答案 0 :(得分:0)
这个问题,我想如果某个编译器警告设置在vs 2015中默认使用UN初始化变量,所以在使用它之前初始化intInput:
const info = document.querySelector('#modal.modal-info')
const footer = document.querySelector('#modal.modal-footer')
const defaultFooter = 'Please contact help@example.com'
$scope.hideModal = function () {
// Hide modal etc.
}
function displayError (err, optionalInfo) {
if (optionalInfo) {
info.textContent = optionalInfo
footer.textContent = defaultFooter
} else if (err.status >= 500) {
info.textContent = 'We are sorry but our services are currently unavailable'
footer.textContent = 'Please check back soon'
} else {
info.textContent = err.message
info.textContent = 'Please examine your request or contact help@example.com'
}
}