473,221 Members | 2,173 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,221 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 10746
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Epson Barnett | last post by:
I'm working on learning .NET and I'm curious about the reason for using static methods in some cases. Specifically, the string class has a split and a join method, but only the join method is...
16
by: Steve | last post by:
Hi Guys, I have a string which contains data elements separated by spaces. I also have a function which returns the number of characters from the beginning of the string for a given number of...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
11
by: Matt | last post by:
string format formula to write a text file below is not working for me pos 1 to 10 name pos 15 to 30 lastname pos 45 to 75 job Adam smith programmer string fmt = "{1,10}{15-30}{45,75}"...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
10
by: April | last post by:
Hope someone can help me The SQL string i need to use does not work, Who can help me.... Thanks in advance Dim strConn As String Dim strSQL As String
4
by: SeNTry | last post by:
Hi Everyone, My first post here as I just begin to learn programming in general and python in particular. I have all the noobie confused questions, but as I work thru the tutorials I'm sure...
12
by: SQACSharp | last post by:
How can I "convert" from a char to a string. I'm trying to display in the console the Classname and the text in the notepad window. Start notepad and type some text before running the following...
3
by: coconet | last post by:
I have a string like this mystring = "color1:blue;color2:red"; I am tring to convert this into an IDictionary populated like this: color1 blue color2 red My non-working syntax is
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.