代码之家  ›  专栏  ›  技术社区  ›  Cory Dee

C++中未声明的字符串

  •  1
  • Cory Dee  · 技术社区  · 16 年前

    我确信这是一件很简单的事情,但我从来没有在C++中工作过。

    14 C:\dev cpp\maincurl.cpp“字符串” 未声明(首先使用此函数)

    > #include <stdio.h>
    > #include <curl/curl.h>
    > #include <string>
    > #include <iostream>
    > 
    > int main(void) {
    >       string url("http://www.google.com"); //     
    >     system("pause");
    > 
    >     return 0; }
    

    我这里缺什么?

    干杯

    5 回复  |  直到 16 年前
        1
  •  10
  •   Daniel Bingham    16 年前

    您尚未声明命名空间。您需要声明:

    using namespace std;
    

    或者告诉编译器“字符串”在标准命名空间中:

    std::string url("...");
    

    或者您可以声明您专门使用了std::string,并且只使用了std中的std::string,方法是说:

    using std::string;
    
        2
  •  1
  •   wilhelmtell    16 年前

    添加 using namespace std; 在上面 main() 定义。

    另外,你不需要 <stdio.h> 如果你包括 <iostream> . 此外,在C++中,不带参数的函数不需要“ void “论点,只需使用括号,括号之间没有任何内容。

        3
  •  1
  •   HyLian    16 年前

    这是一个反复出现的问题…

    你错过了 std:: 在字符串之前,所以它看起来像 std::string

    那是因为 string 属于 std 如果不使用 using 指令必须指定位置 一串 是。

    或者您可以使用

    using namespace std 或者更方便 using std::string 在使用字符串类之前。

        4
  •  0
  •   TimW    16 年前

    你需要 std::string 或 using std::string .

        5
  •  0
  •   Marcel Gosselin    16 年前

    尝试 std::string url ("http://www.google.com");

    string类位于std命名空间中