471,585 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

string not working in c++

Hello,

I am using visual c++ 6 and i am having problems with string to work.

******** Here is the program project.cpp*********
#include <iostream.h>
#include <string>

#include "stdafx.h"

// This program just inverts the tickers.csv files execpt first line
int main(){

string ticker ;

return 0;
}
***************************

on compiling i get this error message
**************************
Compiling...
StdAfx.cpp
Compiling...
Project.cpp
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'string' :
undeclared identifier
C:\Windows\Desktop\Project\Project.cpp(17) : error C2146: syntax error
: missing ';' before identifier 'ticker'
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'ticker' :
undeclared identifier
Error executing cl.exe.

Project.exe - 3 error(s), 0 warning(s)
****************************

can someone tell me whats wrong here ?

thank you in advance.

Gaurav
Jul 19 '05 #1
6 10579
WW
Gaurav wrote:
#include <iostream.h>
Drop the .h!
#include <iostream>
#include <string>

string ticker ;


std::string ticker;

--
WW aka Attila
Jul 19 '05 #2
"Gaurav" <ba********@hotmail.com> wrote in message
news:42*************************@posting.google.co m...
Hello,

I am using visual c++ 6 and i am having problems with string to work.

******** Here is the program project.cpp********* #include <iostream.h>
No such header in standard C++. The header which
declares the standard streams is <iostream> (no .h)
You're not using anything from it anyway, so you
can simply omit this line.
#include <string>
#include "stdafx.h"
A Microsoft specific header, not part of standard C++.
The code you've posted doesn't need it anyway, so
you can omit this line.
// This program just inverts the tickers.csv files execpt first line
Looks to me like all it does (tries to do) is define a string
object, then terminate.
int main(){

string ticker ;
std::string ticker;

return 0;
}
Applying changes I point out, we get:

#include <string>

int main()
{
std::string ticker;
return 0;
}

which will successfully compile without a diagnostic
on a compliant implementation, as well as with VC++ v6.0

***************************

on compiling i get this error message
**************************
Compiling...
StdAfx.cpp
Compiling...
Project.cpp
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'string' :
undeclared identifier
Accurate diagnostic message.
C:\Windows\Desktop\Project\Project.cpp(17) : error C2146: syntax error
: missing ';' before identifier 'ticker'
An artifact of the first message.
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'ticker' :
undeclared identifier
An artifact of the first message.
Error executing cl.exe.
Yup. :-)

Project.exe - 3 error(s), 0 warning(s)
****************************

can someone tell me whats wrong here ?


See above.

-Mike
Jul 19 '05 #3
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<KK*****************@newsread4.news.pas.earth link.net>...
"Gaurav" <ba********@hotmail.com> wrote in message
news:42*************************@posting.google.co m...
Hello,

I am using visual c++ 6 and i am having problems with string to work.

******** Here is the program project.cpp*********
#include <iostream.h>


No such header in standard C++. The header which
declares the standard streams is <iostream> (no .h)
You're not using anything from it anyway, so you
can simply omit this line.
#include <string>


#include "stdafx.h"


A Microsoft specific header, not part of standard C++.
The code you've posted doesn't need it anyway, so
you can omit this line.
// This program just inverts the tickers.csv files execpt first line


Looks to me like all it does (tries to do) is define a string
object, then terminate.
int main(){

string ticker ;


std::string ticker;

return 0;
}


Applying changes I point out, we get:

#include <string>

int main()
{
std::string ticker;
return 0;
}

which will successfully compile without a diagnostic
on a compliant implementation, as well as with VC++ v6.0

***************************

on compiling i get this error message
**************************
Compiling...
StdAfx.cpp
Compiling...
Project.cpp
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'string' :
undeclared identifier


Accurate diagnostic message.
C:\Windows\Desktop\Project\Project.cpp(17) : error C2146: syntax error
: missing ';' before identifier 'ticker'


An artifact of the first message.
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'ticker' :
undeclared identifier


An artifact of the first message.
Error executing cl.exe.


Yup. :-)

Project.exe - 3 error(s), 0 warning(s)
****************************

can someone tell me whats wrong here ?


See above.

-Mike


********************
thanx

It works fine now. i have another problem using vector<string>

#include "stdafx.h"
#include <fstream>
//#include <ofstream.h>
#include <string>
#include <vector>

using namespace std;

// This program just inverts the tickers.csv files execpt first line
int main(){
//string ticker, line;
//string input,output;
//ifstream Tickers( "tickers.txt", ios::in);
//ifstream Input_File;
//ofstream Output_File;
vector<string> temp;
/*
while(Tickers>>ticker){
input = "tempdata/" + ticker + ".csv";
output = "tempdata/" + ticker + "1.csv";
Input_File.open( input.c_str(), ios::in);
Output_File.open ( output.c_str(), ios::app);
while ( Input_File >> line ){
temp.push_back(line);
}
Output_File << temp[0] << endl;
for ( unsigned i = ( temp.size() - 1 ); i > 0; i--)
Output_File << temp[i] << endl;
temp.clear();
Input_File.close();
Output_File.close();

}
*/

return 0;
}
Here effectively i just have vector<string> temp in main, everything
else is commented.

If i compile this program i get following warnings

*********************
Compiling...
project.cpp
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char> const *,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<ch ar,std::char_traits<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
const *,int>' : identifier was truncated to '255' characters in the
debug information
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char> *,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<char,std ::char_traits<char>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
*,int>' : identifier was truncated to '255' characters in the debug
information
c:\program files\microsoft visual studio\vc98\include\vector(39) :
warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<char>,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char>
::vector<std::basic_string<char,std::char_traits< char>,std::allocator<char>
,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char>
' : identifier was truncated to '255' characters in the debug
information
c:\program files\microsoft visual studio\vc98\include\vector(60) :
warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<char>,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char>

::~vector<std::basic_string<char,std::char_traits <char>,std::allocator<char>
,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char>' : identifier was truncated to '255' characters in the debug

information
Linking...

project.exe - 0 error(s), 4 warning(s)
***********************

how can i get rid of these ?

Also if i remove all the comments, i have problems with temp.clear()

All this program is doing is inverting about 40 files, whose names are
in tickers.txt.

thank you in advance.

Gaurav
Jul 19 '05 #4
in the top of the codes
u can do it as following, bcoz not namespace:):
....
#include <string>
....
using namespace std;

void fun()
{
std::string str;
}

"Gaurav" <ba********@hotmail.com> wrote in message
news:42*************************@posting.google.co m...
Hello,

I am using visual c++ 6 and i am having problems with string to work.

******** Here is the program project.cpp*********
#include <iostream.h>
#include <string>

#include "stdafx.h"

// This program just inverts the tickers.csv files execpt first line
int main(){

string ticker ;

return 0;
}
***************************

on compiling i get this error message
**************************
Compiling...
StdAfx.cpp
Compiling...
Project.cpp
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'string' :
undeclared identifier
C:\Windows\Desktop\Project\Project.cpp(17) : error C2146: syntax error
: missing ';' before identifier 'ticker'
C:\Windows\Desktop\Project\Project.cpp(17) : error C2065: 'ticker' :
undeclared identifier
Error executing cl.exe.

Project.exe - 3 error(s), 0 warning(s)
****************************

can someone tell me whats wrong here ?

thank you in advance.

Gaurav

Jul 19 '05 #5
"Gaurav" <ba********@hotmail.com> wrote in message
news:42*************************@posting.google.co m...

It works fine now. i have another problem using vector<string>

#include "stdafx.h"
#include <fstream>
//#include <ofstream.h>
#include <string>
#include <vector>

using namespace std;

// This program just inverts the tickers.csv files execpt first line
int main(){
//string ticker, line;
//string input,output;
//ifstream Tickers( "tickers.txt", ios::in);
//ifstream Input_File;
//ofstream Output_File;
vector<string> temp;
/*
while(Tickers>>ticker){
input = "tempdata/" + ticker + ".csv";
output = "tempdata/" + ticker + "1.csv";
Input_File.open( input.c_str(), ios::in);
Output_File.open ( output.c_str(), ios::app);
while ( Input_File >> line ){
temp.push_back(line);
}
Output_File << temp[0] << endl;
for ( unsigned i = ( temp.size() - 1 ); i > 0; i--)
Output_File << temp[i] << endl;
temp.clear();
Input_File.close();
Output_File.close();

}
*/

return 0;
}
Here effectively i just have vector<string> temp in main, everything
else is commented.

If i compile this program i get following warnings

*********************
Compiling...
project.cpp
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::al
locator<char>
const *,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<ch

ar,std::char_traits<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
const *,int>' : identifier was truncated to '255' characters in the
debug information
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:

'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::al
locator<char>
*,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<char,std

::char_traits<char>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
*,int>' : identifier was truncated to '255' characters in the debug
information
c:\program files\microsoft visual studio\vc98\include\vector(39) :
warning C4786:

'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<ch
ar>
,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocato r<char>

::vector<std::basic_string<char,std::char_traits< char>,std::allocator<char>

,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocato

r<char>
>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(60) :
warning C4786:

'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<ch
ar>
,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocato r<char>

::~vector<std::basic_string<char,std::char_traits <char>,std::allocator<char
,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocato

r<char>
>' : identifier was truncated to '255' characters in the debug

information
Linking...

project.exe - 0 error(s), 4 warning(s)
***********************

how can i get rid of these ?


These can be safely ignored. If you want to hide them look in the MS
documentation for the #pragma method to do this. #pragma is not part of
standard C++, so any detailed questions about this should be directed to a
MS specific newsgroup.
Also if i remove all the comments, i have problems with temp.clear()


What problems exactly.
Jul 19 '05 #6
> If i compile this program i get following warnings

*********************
Compiling...
project.cpp
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char>
const *,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<ch

ar,std::char_traits<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
const *,int>' : identifier was truncated to '255' characters in the
debug information
C:\Windows\Desktop\project\project.cpp(43) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char>
*,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
,std::basic_string<char,std

::char_traits<char>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >
*,int>' : identifier was truncated to '255' characters in the debug
information

[...snip...]

how can i get rid of these ?

Also if i remove all the comments, i have problems with temp.clear()

All this program is doing is inverting about 40 files, whose names are
in tickers.txt.

thank you in advance.

Gaurav


This is a problem with VC. You need to include

#pragma warning(disable: 4786)

at the top of the relevant header files. If there are many then do it in stdafx.h

Cheers,

Chris
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Steve | last post: by
32 posts views Thread by tshad | last post: by
11 posts views Thread by Matt | last post: by
4 posts views Thread by SeNTry | last post: by
12 posts views Thread by SQACSharp | last post: by
3 posts views Thread by coconet | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by

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.