locked
Read form text document RRS feed

  • Question

  • ifstream myfile("Modifyed_sine.txt");
    	if (myfile.is_open())
    	{
    		//ifstream ifs("modifiedtrapeziod.txt");
    		while (getline(myfile, line)) {
    			string total = line;
    			std::size_t found = total.find(' ');
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			lift[loop] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			velocity[loop] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			acceleration[loop] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			string number = total.substr(0, found + 1);
    			int final = atoi(number.c_str());
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			lift[final] = total.substr(0, found);;
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			velocity[final] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			acceleration[final] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			number = total.substr(0, found + 1);
    			final = atoi(number.c_str());
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			lift[final] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			velocity[final] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			acceleration[final] = total.substr(0, found);
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			number = total.substr(0, found + 1);
    			final = atoi(number.c_str());
    			total = total.substr(found + 1);
    			found = total.find(' ');
    			if (final == 120) {
    				lift[final] = total;
    				velocity[final] = "0";
    				acceleration[final] = "0";
    			}
    			else {
    				lift[final] = total.substr(0, found);
    				total = total.substr(found + 1);
    				found = total.find(' ');
    				velocity[final] = total.substr(0, found);
    				total = total.substr(found + 1);
    				found = total.find(' ');
    				acceleration[final] = total.substr(0, found);
    			}
    			
    			total = "";
    			line = "";
    			loop++;
    		}
    		
    		myfile.close();
    	}

    The code opens text as you can see, and import text form text file on disk.

    But I want that integrate in to the clr Project and read them from there, instead from disk.

    Any have a good idea what need to be changed to do that?

    thank you

    Monday, April 27, 2020 11:07 PM

Answers

  • Thank you! Dylan
    • Marked as answer by ollp Tuesday, April 28, 2020 10:48 AM
    Tuesday, April 28, 2020 10:48 AM

All replies

  • Hi ollp,

    >>But I want that integrate in to the clr Project and read them from there, instead from disk.

    Do you want to get relative path of the file, which is inculded in a project?

    If so, you could type this code:

    ifstream myfile(".\\Modifyed_sine.txt"); 
    ifstream myfile(".\\[folder]\\Modifyed_sine.txt");

    Note: ".\\" means that the path of the current vcxproj file. 

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Tuesday, April 28, 2020 5:47 AM
  • Thank you! Dylan
    • Marked as answer by ollp Tuesday, April 28, 2020 10:48 AM
    Tuesday, April 28, 2020 10:48 AM