473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

help with sting and include files ?

this program compiles fine with g++ on linux. But on VC++ 6.0 I am
getting errors like below. I have tried including <cstring> as well

error C2065: string undeclared identifier
s1 undeclared identifier and similarly for s2 as well.

again the same code works just fine with g++ on linux.

#include <iostream>
#include <string>

int main()
{
string s1("hello");
string s2; cin>>s2;
cout<<s2;
cout<<s1<<endl;
return 0;
}
Jul 22 '05 #1
1 1302
"mark" <ma*********@yahoo.com> wrote...
this program compiles fine with g++ on linux.
Whatever version of g++ you got, it's broken.
But on VC++ 6.0 I am
getting errors like below. I have tried including <cstring> as well

error C2065: string undeclared identifier
s1 undeclared identifier and similarly for s2 as well.

again the same code works just fine with g++ on linux.

#include <iostream>
#include <string>
Names of types and objects in C++ Library are declared inside the
'std' namespace. You have to specify it in the name or bring the
used names into the scope where they will become accessible. BTW,
what book on C++ are you reading that doesn't explain that? Was
it published before 1998? Throw it away and get a newer one.

int main()
{
string s1("hello");
string s2; cin>>s2;
cout<<s2;
cout<<s1<<endl;
The four lines above should look like this in Standard C++:

std::string s1("hello");
std::string s2; std::cin>>s2;
std::cout<<s2;
std::cout<<s1<<std::endl;

Or, if you are a bit more attentive to proper use of whitespace:
std::string s1("hello"), s2;
std::cin >> s2;
std::cout << s2;
std::cout << s1 << std::endl;
return 0;
}


Read up on 'namespace' and 'using declaration' ("using" is a keyword)

Victor
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
13
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
2
by: shblack | last post by:
I need help with a program I am writing for school. The program has to do the following: /* 1. Character string must be a minimium of 15 charactors. 2. If not 15 characters long it must give...
2
by: shblack | last post by:
Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.