I am just starting to use Visual Studio C++. Before I was working with UNIX (years ago).
It looks like there are many things that I need to know. I copied a program from CPlusPlus.com and tried to compile it as a CLR console application. This is as far as I got:

// VectorStringCLR.cpp : main project file.

#include "stdafx.h"

#include<cstring>
#include<fstream>
#include<iostream>
#include<vector>

using namespace System;

int main() {
    vector<string> list;

    string word;
    ifstream wordfile("TextFile1.txt");
    while (wordfile >> word) {
        list.push_back(word);
    }

    for (unsigned n=0; n<list.size(); ++n) {
        cout << list.at( n ) << " ";
    }
    return 0;
}

When I tried to compile it here are the errors that I recieved:

1>------ Rebuild All started: Project: VectorStringCLR, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'VectorStringCLR', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>AssemblyInfo.cpp
1>VectorStringCLR.cpp
1>.\VectorStringCLR.cpp(13) : error C2065: 'vector' : undeclared identifier
1>.\VectorStringCLR.cpp(13) : error C2065: 'string' : undeclared identifier
1>.\VectorStringCLR.cpp(13) : error C2065: 'list' : undeclared identifier
1>.\VectorStringCLR.cpp(15) : error C2065: 'string' : undeclared identifier
1>.\VectorStringCLR.cpp(15) : error C2146: syntax error : missing ';' before identifier 'word'
1>.\VectorStringCLR.cpp(15) : error C2065: 'word' : undeclared identifier
1>.\VectorStringCLR.cpp(16) : error C2065: 'ifstream' : undeclared identifier
1>.\VectorStringCLR.cpp(16) : error C2146: syntax error : missing ';' before identifier 'wordfile'
1>.\VectorStringCLR.cpp(16) : error C3861: 'wordfile': identifier not found
1>.\VectorStringCLR.cpp(17) : error C2065: 'wordfile' : undeclared identifier
1>.\VectorStringCLR.cpp(17) : error C2065: 'word' : undeclared identifier
1>.\VectorStringCLR.cpp(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Generating Code...
1>Build log was saved at "file://c:\Users\Grace\Documents\Visual Studio 2008\Projects\VectorStringCLR\VectorStringCLR\Debug\BuildLog.htm"
1>VectorStringCLR - 12 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Okay. I am sure that I *REALLY* need some idea what I am doing. I am very ignorant
about Visual Studio, so please could someone GENTLY explain where I should begin
here. I am a bit embarrassed here. I am frustrated. Not giving up, but just trying
to find a simple way to read lines of data out of a file. In the next step I was
going to collect pointers to each element and the parse the lines for strings in them that would be separated by comas.

But as you see I gave up at this point. I suspect that there is something really wrong
with the way I am trying to use Visual Studio here.

Any Advice for this VS Newbie?

Try searching those errors in google.
http://msdn.microsoft.com/es-es/library/ewcf0002(v=vs.80).aspx
You need the "std" namespace for string and vector. You can either add a line with "using namespace std" or replace "vector" by "std::vector" and so on for each string.

Thank You for your response teo236! I will have a look at the MSDN url that You mentioned.

Okay I changed it to:

using namespace std;

The following errors where produced:

----- Rebuild All started: Project: VectorStringCLR, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'VectorStringCLR', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>VectorStringCLR.cpp
1>.\VectorStringCLR.cpp(17) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1146): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1148): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1150): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(348): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(367): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(386): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(404): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(422): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::ifstream, std::string)'
1>.\VectorStringCLR.cpp(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>AssemblyInfo.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Users\Grace\Documents\Visual Studio 2008\Projects\VectorStringCLR\VectorStringCLR\Debug\BuildLog.htm"
1>VectorStringCLR - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Thanks Again teo236!

It looks like you can't use the '<<' operator with strings. try using the function c_str() from string:

cout << list.at( n ).c_str() << " ";

After you've finished correcting these errors, I will ask if you're interested in seeing the actual CLR version of the same code which looks like:

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::IO;

int main(array<System::String ^> ^args)
{
   List<String^>^ lst_strData = gcnew List<String^>();
   StreamReader^ fileIn = gcnew StreamReader("TextFile1.txt");
   while(!fileIn->EndOfStream)
   {
      lst_strData->Add(fileIn->ReadLine());
   }
   fileIn->Close();

   for each(String^ strData in lst_strData)
   {
      Console::WriteLine(strData);
   }

   return 0;
}

Thines01:

Thank you for your response. I wonder in this case if it would be possible for each
string to know a pointer to the string so that you have code to parse that string
delimited into parts by comas?

Anyway I am trying to learn quickly - I have a project that I am working on in which
I will need to become fairly comfortable quickly to succeed.

Thanks Again

Sorry for the delayed response:

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::IO;

int main(array<System::String ^> ^args)
{
   List<String^>^ lst_strData = gcnew List<String^>();
   StreamReader^ fileIn = gcnew StreamReader("TextFile1.txt");
   while(!fileIn->EndOfStream)
   {
      lst_strData->Add(fileIn->ReadLine());
   }
   fileIn->Close();

   for each(String^ strData in lst_strData)
   {
      array<String^>^ arr_str = strData->Split(',');
      
      for each(String^ s in arr_str)
      {
         Console::WriteLine(s->Trim());
      }
   }

   return 0;
}

// 73s de KC0TOM

thines01 - Thank You for your help. I will consider this in the context of what I must do. I appreciate all of the help that I am getting here. My project may require some che in stratagy to reach the results desired. I am re-thin can be accomplished.

Best regards - Thank You again.

thines01,

Thank You for Your kind help. Thomas, I will probably need to re-evaluate how I am to achieve the objective of this project. I will consider what I have learned so far and try to publish in this thread my final solution. I certainly am surprised that C++ Visual Studio seems to be so restricted as not much seems to work as I expected. I may just go back to using simple C code as apposed to C++ or Assembler. Actually this will save me some time on the learning curve but I realize that C++ is full of great features. Perhaps after I have a functional program I will make use of some or many of these advantages. I see that You are a Ham. My Call is KC0BTM (previous: WB3ETS, VK3JAX others). Thanks again for Your help.

Remember, you can still use all of the features of C inside a C++ app. For Visual Studio, there will be some special settings you have to use though.

You can still use FILE* and fopen() and sprintf() all of that (ha ha)...
I like the new syntax as I don't have to do as much memory management (unless I want to).

I write a lot in C#. Most of the new syntax is similar or equivalent to C#, so I can code in either language with pretty-much the same commands.

Yes, at first, there is a large adjustment to use the newer style of VS, but if you remember the days of creating your own makefile and linker settings, the pain was fairly the same.

On the HAM issue... I saw the 73s in your signature and it made me curious about you :) . You can see my details on QRZ or the Universal Licensing System

I Have seen You on QRZ - A coincidence : You Live in Belton, I live in Belltown (a close suburb and a part of Seattle). Synchronicity is fun, isn't it! Also by the way, I worked extensively on EMACS for the PC. Makefiles, Make, NMAKE And All of that where the way I needed to generate my code. Also doing builds of Mozilla, Firefox, Thunderbird and Audacity. Crazy huh? Since 1972 and Xerox Sigma-7 and MIT ITS with PDP-6 front-ended to PDP-10s. Also worked with Tymshare (Tymnet) [14+Yrs - Here and global in HK and OZ] using their proprietary DEC PDP-10 Software and SAIL. Oh how things have changed and stayed the same. Nice to meet You. My Blessings go out to You and Your Family. Stay Well please!

73
-Grace
NNNN
z

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.