C++ 为什么这个基本的cin会阻止我的程序编译?
我已经包含并正在使用标准名称空间,当我将文件名硬编码到中时,程序运行得很好,但是当我输入cin VS时,会出现奇怪的错误。 为了清楚起见,我特别谈论的是cin>>sodokuFile系列C++ 为什么这个基本的cin会阻止我的程序编译?,c++,C++,我已经包含并正在使用标准名称空间,当我将文件名硬编码到中时,程序运行得很好,但是当我输入cin VS时,会出现奇怪的错误。 为了清楚起见,我特别谈论的是cin>>sodokuFile系列 cout << "Assignment 2\n\n"; ifstream ins; cout << "Please enter the Sokoku file\n"; string sodokuFile; cin >> sodokuFile; ins.open(sodokuF
cout << "Assignment 2\n\n";
ifstream ins;
cout << "Please enter the Sokoku file\n";
string sodokuFile;
cin >> sodokuFile;
ins.open(sodokuFile.c_str());
if(ins.is_open())
{
int num;
//counting numbers displayed horizontally
int counth = 0;
//counting numbers displayed vertically
int countv = 0;
while (ins >> num)
{
cout << num << " ";
counth++;
//placing vertical lines
if(counth %3 == 0)
{
cout << "| ";
}
//making line breaks for new rows
if(counth == 9)
{
cout << "\n\n";
counth = 0;
countv++;
//horizontal lines
if(countv %3 == 0)
{
cout << "_________________________________________\n";
}
}
}
}
else
{
cout << "File does not exist\n";
return 0;
}
return 0 ;
下面是编译器中唯一看起来有用的错误
错误C2679:二进制“>>”:未找到接受“std::string”类型的右操作数的运算符,或者没有可接受的转换
#include <string>
因为字符串头声明运算符>>istream&,string&.您需要将
#include <string>
因为字符串头声明操作符>>istream&,string&.哦,奇怪的错误,而不是普通的错误。。。可能是编译器的错误。如果有办法知道这些错误是什么的话。第一个错误是什么?不确定为什么会出现错误,但cin会在最后一行给你一个单词。如果你写Hello world,那么你只会得到Hello,你可能应该使用:std::getlinestd::cin,std::string@KerrekSB我想人们一定认为,因为这些错误对他们没有帮助,所以它们对任何人都没有帮助。@ZarakiKenpachi:现在肯定没有人会在文件名中加空格,是吗?!哦,奇怪的错误,与普通错误相反。。。可能是编译器的错误。如果有办法知道这些错误是什么的话。第一个错误是什么?不确定为什么会出现错误,但cin会在最后一行给你一个单词。如果你写Hello world,那么你只会得到Hello,你可能应该使用:std::getlinestd::cin,std::string@KerrekSB我想人们一定认为,因为这些错误对他们没有帮助,所以它们对任何人都没有帮助。@ZarakiKenpachi:现在肯定没有人会在文件名中加空格,是吗?!