Cory Dee
Cory Dee

Reputation: 2891

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

Upvotes: 1

Views: 5300

Answers (5)

Daniel Bingham
Daniel Bingham

Reputation: 12914

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;

Upvotes: 10

HyLian
HyLian

Reputation: 5093

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.

Upvotes: 1

wilhelmtell
wilhelmtell

Reputation: 58667

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.

Upvotes: 1

Marcel Gosselin
Marcel Gosselin

Reputation: 4716

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

the string class is in std namespace

Upvotes: 0

TimW
TimW

Reputation: 8447

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

Upvotes: 0

Related Questions