开发者

String Undeclared In C++

开发者 https://www.devze.com 2022-12-10 22:53 出处:网络
I\'m sure this is a really simple thing, but I haven\'t worked in C++ forever. 14 C:\\Dev-Cpp\\mainCurl.cpp `string\'

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)

> #开发者_如何学JAVAinclude <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;


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.


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.


You need std::string or using std::string.


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

the string class is in std namespace

0

精彩评论

暂无评论...
验证码 换一张
取 消