Sign in to follow this  
Followers 0
Negat1ve

Array

16 posts in this topic

#1 ·  Posted (edited)

hi there , i m trying to make something like this:

String^ Line;

int LineN = 1;

StreamReader^ OpenScr = File::OpenText ("fishing.l2s");

while ((Line + LineN = OpenScr->ReadLine()) !=nullptr)

{

LineN = LineN +1;

}

OpenScr->Close();

MessageBox::Show("Line 1",Line1,MessageBoxButtons:OK);

MessageBox::Show("Line 2",Line2,MessageBoxButtons:OK);

i would like to attach each text of line to variable Line(line number) Line1;Line2 and so on...

But with the code i posted i will get error:

error C2106: '=' : left operand must be l-value

Edited by Negat1ve

Share this post


Link to post
Share on other sites



I'm guessing that you want the AutoIt code.

#include<file.au3>
$aArray = _FileReadToArray(@ScriptDir & "\fishing.l2s")
For $i = 1 to Ubound($aArray) -1
    MsgBox(4096, "Results", "line " & $i & " = " & @CRLF & $aArray[$i])
Next

This should have been aske in the General support forum. Not in Dev chat


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

This is C++ code , and i want to know how can i do it in C++ , not in autoit OMG...

Share this post


Link to post
Share on other sites

Sorry 'bout that. It's 04:35 and I've been at it now for over 22 hours.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

hi there , i m trying to make something like this:

String^ Line;

int LineN = 1;

StreamReader^ OpenScr = File::OpenText ("fishing.l2s");

while ((Line + LineN = OpenScr->ReadLine()) !=nullptr)

{

LineN = LineN +1;

}

OpenScr->Close();

MessageBox::Show("Line 1",Line1,MessageBoxButtons:OK);

MessageBox::Show("Line 2",Line2,MessageBoxButtons:OK);

i would like to attach each text of line to variable Line(line number) Line1;Line2 and so on...

But with the code i posted i will get error:

error C2106: '=' : left operand must be l-value

What language is this? This is not any version C++ that I recognize. In fact, I don't know a language that puts a caret (^) at the end of class names in declarations.

So, you want to create a set of variables that have the text of a file stored in them, with the file lines being ordinal to the variable. In C++ you would need to create an array or similar storage structure. C++ does not have the ability to dynamically create variables; they must all be declared before use.

Here is an example. This code will typically work with ASCII characters, not Unicode, because I am using that implementation of the string class. I will use a dynamic array called a vector to store the array of file lines.

// Example of reading a file
#include <iostream>  // for cout
#include <fstream>   // for ifstream
#include <string>    // for string
#include <vector>    // for vector template

int main(void) {  // don't need to pay attention to the command line.
    string sLine;
    vector<string> vsFile;
    ifstream ifsFile("fishing.l2s");  // try to open the file, ready for reading.

    if (ifsFile.fail()) {
        // Can not open file.
        return 1;    // exit program with error status.
    }
    // You should try to estimate the number of lines in the file here.  I am estimating 100 lines.  This can reduce the number of reallocations.
    vsFile.reserve(100);

    while (!(ifsFile.eof())) {    // keep reading until end of file.
        ifsFile.getline(sLine);   // read the line
        vsFile.push_back(sLine);  // store in the vector.
    }
    ifsFile.close();
    // vsFile now contains all the lines of the file.
    cout << vsFile[0] << '\n';  // line 1
    cout << vsFile[1] << '\n';  // line 2
    // What do you want to do now?

    // end of function
    return 0;   // exit the program indicating normal exit.
}

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

That language is MS visual C++ 2008 express edition , so your code may not be fully compabitile.. but thanks it also helped a little.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That language is MS visual C++ 2008 express edition , so your code may not be fully compabitile.. but thanks it also helped a little.

Sorry, but no. First of all, Microsoft did not write their own version of C++ (and call it C++, at any rate). Second, Microsoft's compiler is pretty good now-a-days about standards compliance. In other words, if you're using MSVC then you're (supposed to be) writing standard C++ targeted towards the Windows API with a few additional Windows-centric extensions to the language. Second, as David has already pointed out, that is not valid C++ syntax. Nor is that any recognizable File or GUI class/namespace. While I can certainly figure out what nullptr is, that's also not the standard way of handling it (hint: See NULL).

Given that you don't really seem to know what language you are using, I'm not sure you're ready for Windows-specific stuff. I think you're trying to skip some steps here.

Edit: Also, LoL at suggesting the standards compliant code written by a C++ professor won't be compatible with your compiler. That's rich.

Edited by Valik

Share this post


Link to post
Share on other sites

It's Managed C++. It's the C++.Net stuff.

^ means it's a managed pointer and will be garbage collected.

while ((Line + LineN = OpenScr->ReadLine()) !=nullptr)

This line is obviously wrong. It looks like you are trying to do something like setting the variable "Line1", "Line2", "Line3" etc to values. It does not work this way. Ever.

Create a list instead.

System::Collections::Generic::List<String^> ^mylist = gcnew System::Collections::Generic::List<String^>();
while ((Line = OpenScr->ReadLine()) != nullptr)
{
    mylist->Add(Line);
}

// line 1 is mylist[0], line2 is mylist[1], etc

Share this post


Link to post
Share on other sites

The OP should be using C#, then.

Share this post


Link to post
Share on other sites

Sorry, but no. First of all, Microsoft did not write their own version of C++ (and call it C++, at any rate). Second, Microsoft's compiler is pretty good now-a-days about standards compliance. In other words, if you're using MSVC then you're (supposed to be) writing standard C++ targeted towards the Windows API with a few additional Windows-centric extensions to the language. Second, as David has already pointed out, that is not valid C++ syntax. Nor is that any recognizable File or GUI class/namespace. While I can certainly figure out what nullptr is, that's also not the standard way of handling it (hint: See NULL).

Given that you don't really seem to know what language you are using, I'm not sure you're ready for Windows-specific stuff. I think you're trying to skip some steps here.

This code is working fine if i remove + LineN from while loop !!!! so dont say that it is wrong.. and this is microsoft visual c++

http://www.microsoft.com/express/

It's Managed C++. It's the C++.Net stuff.

^ means it's a managed pointer and will be garbage collected.

while ((Line + LineN = OpenScr->ReadLine()) !=nullptr)

This line is obviously wrong. It looks like you are trying to do something like setting the variable "Line1", "Line2", "Line3" etc to values. It does not work this way. Ever.

Create a list instead.

Thanks...

Share this post


Link to post
Share on other sites

The program you are using is Microsoft Visual C++. The language you are using is Managed C++. Please learn the difference between your tool and your language. Thanks.

Share this post


Link to post
Share on other sites

Managed C++ is for interop between native applications and the managed framework. For example, to write a .Net dll but call it via DllCall. It's rather inefficient if you're not trying to allow a native application to access the framework.

Share this post


Link to post
Share on other sites

one more noob question :D what command is for running applications ? like in autoit Run()

Share this post


Link to post
Share on other sites

The easiest would be System::Diagnostics::Process::Start() in .Net.

Share this post


Link to post
Share on other sites

The easiest would be System::Diagnostics::Process::Start() in .Net.

THANKS !!!!

Share this post


Link to post
Share on other sites

If you don't even know simple things like what have been discussed here, should you really by trying to write Managed C++?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0