简体   繁体   中英

String Undeclared In C++

I'm sure this is a really simple thing, but I haven't worked in C++ forever.

14 C:\\Dev-Cpp\\mainCurl.cpp `string' undeclared (first use this function)

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

What am I missing here?

Cheers

You haven't declared your namespace. You need to either declare:

using namespace std;

Or tell the compiler that "string" is in the standard namespace:

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

Or you can announce that you are specifically using std::string and only std::string from std by saying:

using std::string;

This a so recurring problem...

You missed std:: before string, so it will look like std::string

That's because string belongs to std namespace and if you don't use using directive you must specify where string is.

Alternatively you can use

using namespace std ; or more conveniently using std::string before using string class.

Add using namespace std; above the main() definition.

Also, you don't need <stdio.h> if you include <iostream> . Also, in C++ a function that doesn't take arguments doesn't need a " void " argument, simply use parentheses with nothing in between them.

您需要std::stringusing std::string

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

the string class is in std namespace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM