Negat1ve Posted August 26, 2009 Share Posted August 26, 2009 (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 August 26, 2009 by Negat1ve Link to comment Share on other sites More sharing options...
GEOSoft Posted August 26, 2009 Share Posted August 26, 2009 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!" Link to comment Share on other sites More sharing options...
Negat1ve Posted August 26, 2009 Author Share Posted August 26, 2009 This is C++ code , and i want to know how can i do it in C++ , not in autoit OMG... Link to comment Share on other sites More sharing options...
GEOSoft Posted August 26, 2009 Share Posted August 26, 2009 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!" Link to comment Share on other sites More sharing options...
Nutster Posted August 26, 2009 Share Posted August 26, 2009 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 NuttallNuttall 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... Link to comment Share on other sites More sharing options...
Negat1ve Posted August 26, 2009 Author Share Posted August 26, 2009 That language is MS visual C++ 2008 express edition , so your code may not be fully compabitile.. but thanks it also helped a little. Link to comment Share on other sites More sharing options...
Valik Posted August 26, 2009 Share Posted August 26, 2009 (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 August 26, 2009 by Valik Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 26, 2009 Share Posted August 26, 2009 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 Link to comment Share on other sites More sharing options...
Valik Posted August 26, 2009 Share Posted August 26, 2009 The OP should be using C#, then. Link to comment Share on other sites More sharing options...
Negat1ve Posted August 26, 2009 Author Share Posted August 26, 2009 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... Link to comment Share on other sites More sharing options...
Valik Posted August 26, 2009 Share Posted August 26, 2009 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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 27, 2009 Share Posted August 27, 2009 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. Link to comment Share on other sites More sharing options...
Negat1ve Posted August 27, 2009 Author Share Posted August 27, 2009 one more noob question what command is for running applications ? like in autoit Run() Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 27, 2009 Share Posted August 27, 2009 The easiest would be System::Diagnostics::Process::Start() in .Net. Link to comment Share on other sites More sharing options...
Negat1ve Posted August 27, 2009 Author Share Posted August 27, 2009 The easiest would be System::Diagnostics::Process::Start() in .Net.THANKS !!!! Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 27, 2009 Share Posted August 27, 2009 If you don't even know simple things like what have been discussed here, should you really by trying to write Managed C++? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now