Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误C3861:&x27;getLine';:找不到标识符_C++_String_Getline - Fatal编程技术网

C++ 错误C3861:&x27;getLine';:找不到标识符

C++ 错误C3861:&x27;getLine';:找不到标识符,c++,string,getline,C++,String,Getline,我从SEE开始编程抽象(CS106B)。我开始这项任务很困难。这是热身练习的代码。我已经参考了各种不同的解决方案,但没有一个有效,因此,我不得不在这里发布这篇文章 #include <iostream> #include <cstring> #include "console.h" using namespace std; /* Constants */ const int HASH_SEED = 5381; /* Starting poi

我从SEE开始编程抽象(CS106B)。我开始这项任务很困难。这是热身练习的代码。我已经参考了各种不同的解决方案,但没有一个有效,因此,我不得不在这里发布这篇文章

#include <iostream>
#include <cstring>
#include "console.h"
using namespace std;

/* Constants */

const int HASH_SEED = 5381;               /* Starting point for first cycle */
const int HASH_MULTIPLIER = 33;           /* Multiplier for each cycle      */
const int HASH_MASK = unsigned(-1) >> 1;  /* All 1 bits except the sign     */

/* Function prototypes */

int hashCode(string name);

/* Main program to test the hash function */

int main() {
   string name = getLine("Please enter your name: ");
   int code = hashCode(name);
   cout << "The hash code for your name is " << code << "." << endl;
   return 0;
}

/*
 * Function: hash
 * Usage: int code = hashCode(key);
 * --------------------------------
 * This function takes the key and uses it to derive a hash code,
 * which is nonnegative integer related to the key by a deterministic
 * function that distributes keys well across the space of integers.
 * The general method is called linear congruence, which is also used
 * in random-number generators.  The specific algorithm used here is
 * called djb2 after the initials of its inventor, Daniel J. Bernstein,
 * Professor of Mathematics at the University of Illinois at Chicago.
 */

int hashCode(string str) {
   unsigned hash = HASH_SEED;
   int nchars = str.length();
   for (int i = 0; i < nchars; i++) {
      hash = HASH_MULTIPLIER * hash + str[i];
   }
   return (hash & HASH_MASK);
}

首先,您必须包含标题
,而不是

#包括

其次是使用
getline
而不是
getline
。并且参数的类型和数量指定不正确。也许您想使用其他用户定义的函数getLine。

快速翻阅CS106B主页上的文档(我知道这听起来不太可信,但确实如此),可以发现您应该

 #include "simpio.h"  

我建议您将文档添加到书签中;它会使你免于许多深夜作业的恐慌。

<代码> GETLILE()/<代码>不是标准的C或C++函数。在C++标准库和POSIX C库中有各种形式的<代码> GETLILE()/<代码>。C是区分大小写的语言;C++也是如此。同样,用C和C++进行双重标记会导致愤怒(在那些试图回答的部分)或混乱(在那些试图理解的部分),因为它们是非常不同的语言。Google“C++ GETLIN”直接引导我到@克里斯<代码> GETLION>代码>不是<代码> GETLION>代码>…@ USER据我们所知,
getLine
是不存在的。我认为这是一个打字错误/误解。在这方面我似乎是错的:pHi,我为问题和标签中出现这么多错误而道歉。我是第一次使用,所以需要一些时间来熟悉网站。参见代表(斯坦福工程处处)。呸。谢谢我应该能看穿它的。无论如何,感谢您的解决方案和建议!
#include <string>
 #include "simpio.h"