Dear Friends,
I want this code get "t" 9 times from input.txt at desktop and save the acc(t) results in array [3][3] forms in output.text file in desktop. But while running it shows different than I expect. I made a text file in desktop and wrote:
2
3
4
5
6
7
8
9
10
But this code output is: 10 20 30 40 50 60 70 80 90 100
I want to see the results in
20 30 40
50 60 70
80 90 100
form.
I've corrected your code. It seems that you were over-complicating things a little bit; you didn't really need a 2-dimensional array so I changed it into a single dimensional one.
I tried to keep the code as simple as possible, but if there is something you wish me to explain such as what something does or why I did it then I will be happy to.
Did you put "#include <string>" at the top like I did? If you did then the error will be because one of the lines in the file is not an integer. Other than that, the code works flawlessly for me.
6:44:17 **** Incremental Build of configuration Debug for project test 12 ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o main12.o "..\\main12.cpp"
..\main12.cpp: In function 'int acc(std::string)':
..\main12.cpp:16:19: error: 'stoi' was not declared in this scope
return (10*stoi(x)); // "stoi" converts a string into an integer
^
..\main12.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
If you are using g++ then you have to set the compiler options to support C++11 because "stoi" is a new feature. But other than that there should be no other issues. As long as you include the "string" header and use the "std" namespace as well then you should be fine.
What compiler are you using? You can use an alternative compiler such as Eclipse which does support C++11 functions and is also free. If you don't want to use Eclipse then there are plenty of other C++11 compilers hanging around on the internet.